⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form4.cs

📁 由于本系统为一个公司销售管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
                try
                {
                    if (cflag1)
                    {
                        SqlConnection conn = new SqlConnection("server=;database=ll;uid=sa;pwd=;");
                        string add = "alter   table   storage  add   " + textBox2.Text + " " + textBox3.Text + "";
                        ds = new DataSet();
                        q = new SqlDataAdapter(add, conn);
                        q.Fill(ds, "storage");
                        comboBox1.Items.Insert(comboBox1.Items.Count, textBox2.Text);
                    }
                    else if (cflag3)
                    {
                        SqlConnection conn = new SqlConnection("server=;database=ll;uid=sa;pwd=;");
                        string add = "alter   table  sell  add   " + textBox2.Text + " " + textBox3.Text + "";
                        ds = new DataSet();
                        q = new SqlDataAdapter(add, conn);
                        q.Fill(ds, "sell");
                        sc.Items.Insert(sc.Items.Count, textBox2.Text);
                    }
                    else
                    {
                        SqlConnection conn = new SqlConnection("server=;database=ll;uid=sa;pwd=;");
                        string add = "alter   table   users  add   " + textBox2.Text + " " + textBox3.Text + "";
                        ds = new DataSet();
                        q = new SqlDataAdapter(add, conn);
                        q.Fill(ds, "users");
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show("Add error!");
                    return;
                }
                MessageBox.Show("Add successful!");
                textBox2.Text = "";
                textBox3.Text = "";
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            count++;
            if (count % 2 != 0) cflag = true;
            else cflag = false;
        }

     

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            count2++;
            if (count2 % 2 != 0) cflag2 = true;
            else cflag2 = false;
        }

   
        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            cflag1 = true;
            cflag3 = false;
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            cflag3 = true;
            cflag1 = false;
        }

        private void selectSellsToolStripMenuItem_Click(object sender, EventArgs e)
        {
           
            f();
            f1(true);
            dataGridView3.Enabled = true;
            dataGridView3.Visible = true;
            panel1.Visible = false;
            panel2.Visible = false;
            panel3.Visible = false;
        }
        public void f()
        {
            dataGridView1.Enabled = false;
            dataGridView1.Visible = false;
            button3.Enabled = false;
            button4.Enabled = false;
            button3.Visible = false;
            button4.Visible = false;
            button1.Enabled = false;
            button1.Visible = false;
            button2.Enabled = false;
            button2.Visible = false;
            button5.Enabled = false;
            button5.Visible = false;
            textBox1.Enabled = false;
            textBox1.Visible = false;
            button6.Enabled = false;
            button6.Visible = false;
            textBox2.Enabled = false;
            textBox2.Visible = false;
            textBox3.Enabled = false;
            textBox3.Visible = false;
            label1.Enabled = false;
            label1.Visible = false;
      //      dataGridView7.Enabled = false;
      //      dataGridView7.Visible = false;
            dataGridView4.Enabled = false;
            dataGridView4.Visible = false;
            dataGridView3.Enabled = false;
            dataGridView3.Visible = false;
            checkBox1.Enabled = false;
            checkBox1.Visible = false;
            checkBox3.Enabled = false;
            checkBox3.Visible = false;
     //       dataGridView4.Enabled = false;
     //       dataGridView4.Visible = false;
            dataGridView2.Enabled = false;
            dataGridView2.Visible = false;
            radioButton1.Enabled = false;
            radioButton1.Visible = false;
            radioButton2.Enabled = false;
            radioButton2.Visible = false;
            button10.Enabled = false;
            button10.Visible = false;
            textBox10.Visible = false;
        }

        private void sb_Click(object sender, EventArgs e)
        {
            if ((st.Text == "" && sc1.Text != "") || (st.Text != "" && sc1.Text == "")||(sc.Text==""&&(sc1.Text==""||st.Text=="")))
            {
                MessageBox.Show("Input error!");
                return;
            }
            else
            {
                try
                {
                    string select;
                   SqlConnection conn = new SqlConnection("server=;database=ll;uid=sa;pwd=;");
                   if (sc.Text == "*") select = "select * from sell";
                   else if (sc.Text != "price" && sc.Text != "scount") { select = "select * from sell where " + sc.Text + " " + sc1.Text + "  '" + st.Text + "'"; }
                   else if (sc.Text == "scount") { select = "select * from sell where  " + sc.Text + "  " + sc1.Text + "  " + int.Parse(st.Text) + ""; }
                   else { select = "select * from sell where  " + sc.Text + "  " + sc1.Text + "  " + float.Parse(st.Text) + ""; }
                   ds = new DataSet();
                   q = new SqlDataAdapter(select, conn);
                   q.Fill(ds, "sell");
                   dataGridView3.DataSource = ds.Tables[0];
                }
                catch(IndexOutOfRangeException)
                {
                    MessageBox.Show("Select error!");
                     return;
                }
                MessageBox.Show("Select successful!");

            }
        }

        private void sellsInforToolStripMenuItem_Click(object sender, EventArgs e)
        {
            f();
            f1(false);
            panel1.Visible = false;
            panel2.Visible = false;
            panel3.Visible = false;
        }

        private void insertSellsToolStripMenuItem_Click(object sender, EventArgs e)
        {

            f();
            f1(false);
            panel1.Visible = true;
            panel2.Visible = true;
            panel3.Visible = false;
        }

        public void f1(bool b)
        {
            st.Enabled =b ;
            st.Visible = b;
            sc.Enabled = b;
            sc.Visible = b;
            sc1.Enabled = b;
            sc1.Visible = b;
            sb.Enabled = b;
            sb.Visible = b;
            sl.Enabled = b;
            sl.Visible = b;
            button10.Enabled = b;
            button10.Visible = b;
            textBox10.Visible = b;
            textBox11.Visible = b;
            label8.Visible = b;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            string select, insert;
            int count;
            SqlConnection conn = new SqlConnection("server=;database=ll;uid=sa;pwd=;");
            if (textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || textBox7.Text == ""  || textBox9.Text == "")
            {
                MessageBox.Show("Error:can not null!");
                return;
            }
            else
            {               
                select = "select * from storage where wname ='" + textBox4.Text + "' ";
                ds = new DataSet();
                q = new SqlDataAdapter(select, conn);
                q.Fill(ds, "storage");

                try
                {
                    username = ds.Tables["storage"].Rows[0]["wname"].ToString();

                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show("Commodity do not exist!");
                    return;
                }
                if (float.Parse(textBox9.Text) <float.Parse(ds.Tables["storage"].Rows[0]["price"].ToString()))
                {
                    MessageBox.Show("Price too low!");
                    return;
                }
                if (int.Parse(textBox12.Text) > int.Parse( ds.Tables["storage"].Rows[0]["count"].ToString()))
                {
                    MessageBox.Show("Count is lack!");
                    return;
                }
                else count = int.Parse(ds.Tables["storage"].Rows[0]["count"].ToString()) - int.Parse(textBox12.Text);
                

                try
                {
                    insert = "insert into sell(wname,cname,price,sdate,uname,company,scount,sumprice)  values( '" + textBox4.Text + "','" + textBox5.Text + "'," + float.Parse(textBox9.Text) + ",'" + textBox7.Text + "','" + name + "','" + textBox6.Text + "'," + int.Parse(textBox12.Text) + " ," + float.Parse(textBox9.Text) * int.Parse(textBox12.Text) + ") ";
                   ds2 = new DataSet();
                   q2 = new SqlDataAdapter(insert, conn);
                   q2.Fill(ds2, "sell");
                   string update = "update storage set count = " + count + "  where wname= '" + textBox4.Text + "' and  price= " + ds.Tables["storage"].Rows[0]["price"] + "";
                   SqlDataAdapter q3 = new SqlDataAdapter(update, conn);
                   ds1 = new DataSet();
                   q3.Fill(ds1, "update");
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show("Insert error!");
                    return;
                }            
                MessageBox.Show("Insert successful!");
                textBox4.Text = ""; textBox5.Text = ""; textBox6.Text = "";
                textBox12.Text = ""; textBox9.Text = ""; textBox7.Text = "";
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void mangToolStripMenuItem_Click(object sender, EventArgs e)
        {
            f1(false);
            panel1.Visible = false;
            panel2.Visible = false;
            panel3.Visible = false;
            dataGridView3.Enabled = false;
            dataGridView3.Visible = false;
            dataGridView1.Enabled = false;
            dataGridView1.Visible = false;
            dataGridView2.Enabled = false;
            dataGridView2.Visible = false;
            dataGridView4.Enabled = false;
            dataGridView4.Visible = false;
        }
     
        private void button10_Click_1(object sender, EventArgs e)
        {
            float c;
            if ((st.Text == "" && sc1.Text != "") || (st.Text != "" && sc1.Text == "") || (sc.Text == "" && (sc1.Text == "" || st.Text == "")))
            {
                MessageBox.Show("Error:can not null!");
                return;           
            }
            else
            {
                try
                {
                    string select,select1;
                    select1 = "select * from  sell";
                    SqlConnection conn = new SqlConnection("server=;database=ll;uid=sa;pwd=;");
                    if (sc.Text == "*") select = "select * from sell";
                    else if (sc.Text != "price" && sc.Text != "scount"  && sc.Text != "sumprice") { select = "select * from sell where " + sc.Text + " " + sc1.Text + "  '" + st.Text + "'"; }
                    else if (sc.Text == "scount") { select = "select * from sell where  " + sc.Text + "  " + sc1.Text + "  " + int.Parse(st.Text) + ""; }
                    else select = "select * from sell where  " + sc.Text + "  " + sc1.Text + "  " + float.Parse(st.Text) + "";
                    ds = new DataSet();
                    q = new SqlDataAdapter(select, conn);
                    ds1 = new DataSet();
                    SqlDataAdapter q1 = new SqlDataAdapter(select1, conn);
                    q.Fill(ds, "sell");
                    q1.Fill(ds1, "sell");
                    dataGridView3.DataSource = ds.Tables[0];
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show("Select error!");
                    return;
                }
                MessageBox.Show("Account successful!");
                textBox10.Text = ds.Tables[0].Rows.Count.ToString();
                c = (float.Parse(ds.Tables[0].Rows.Count.ToString()) / float.Parse(ds1.Tables[0].Rows.Count.ToString())) * 100;
                textBox11.Text = c.ToString();
            } 

        }

        private void accountToolStripMenuItem_Click(object sender, EventArgs e)
        {
            f1(false);
            dataGridView3.Visible = false;
            panel1.Visible = false;
            panel2.Visible = false;
            panel3.Visible = false;
            Form3 fm3=new Form3();
            fm3.Show();

        }

        private void storageInfoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            panel3.Visible = true;
            f();
            f1(false);
            panel1.Visible = false;
            panel2.Visible = false;
        }

        private void button9_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("server=;database=ll;uid=sa;pwd=;");
            string select = "select * from storage";
            q = new SqlDataAdapter(select, conn);
            ds = new DataSet();
            q.Fill(ds, "sell");        
            dataGridView5.DataSource = ds.Tables[0];
            cflag4=true; 
        }
        private void button11_Click(object sender, EventArgs e)
        {
            if (cflag4)
            {
                SqlCommandBuilder SCB = new SqlCommandBuilder(q);
                q.Update(ds, "storage");
            }
            else return;           
        }

        private void button12_Click(object sender, EventArgs e)
        {
            if ((textBox12.Text == "" && comboBox2.Text != "") || (textBox12.Text != "" && comboBox2.Text == "") || (comboBox1.Text == "" && (comboBox2.Text == "" || textBox12.Text == "")))
            {
                MessageBox.Show("Input error!");
                return;
            }
            else
            {
                try
                {
                    string select;
                    SqlConnection conn = new SqlConnection("server=;database=ll;uid=sa;pwd=;");
                    if (comboBox1.Text == "*") select = "select * from storage";
                    else if (comboBox1.Text != "price"&& comboBox1.Text != "count") { select = "select * from storage where " + comboBox1.Text + " " + comboBox2.Text + "  '" + textBox12.Text + "'"; }
                    else if (comboBox1.Text == "price") { select = "select * from storage where  " + comboBox1.Text + "  " + comboBox2.Text + "  " + float.Parse(textBox12.Text) + ""; }
                    else select = "select * from storage where  " + comboBox1.Text + "  " + comboBox2.Text + "  " + int.Parse(textBox12.Text) + ""; 
                    ds = new DataSet();
                    q = new SqlDataAdapter(select, conn);
                    q.Fill(ds, "storage");
                    dataGridView5.DataSource = ds.Tables[0];
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show("Select error!");
                    return;
                }
                MessageBox.Show("Select successful!");

            }
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -