コード例 #1
0
 private void button1_Click_1(object sender, EventArgs e)
 {
     if (this.textBox1.Text.Length == 0)
     {
         MessageBox.Show("请输入用户密码");
     }
     else
     {
         string sql   = string.Format("select count(*)from Logging where UserName='******'and passWord='******'", this.comboBox1.Text, this.textBox1.Text);
         object o     = DBHelper.getSingle(sql);
         int    count = Convert.ToInt32(o);
         if (count > 0)
         {
             this.DialogResult = DialogResult.OK;
             Main m = new Main();
             m.ShowDialog();
         }
         else
         {
             MessageBox.Show("登录失败");
         }
     }
 }
コード例 #2
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            //ADD SALES
            if (e.KeyData == Keys.F1)
            {
                this.Hide();
                addsales display = new addsales();
                display.ShowDialog();

                /*if (txtcustid.Text == "" || txtprodcode.Text == "" || txtdiscount.Text == "" || txtprice.Text == "" || txtquantity.Text == "")
                 * {
                 *  MessageBox.Show("All fields cannot be EMPTY!", "Error");
                 *  return;
                 * }
                 * int left = Convert.ToInt32(txtleftitem.Text);
                 * if (left == 0)
                 * {
                 *  MessageBox.Show("Please be warned! \nthe product you selected maybe out numbered Please contact Supplier", "Warning!");
                 *  return;
                 * }
                 * if (left < 0)
                 * {
                 *  MessageBox.Show("There is no Item Left", "Warning!");
                 *  return;
                 *
                 * }
                 *
                 * try
                 * {
                 *  conn.dbcon();
                 *  SqlCommand cm = new SqlCommand("INSERT INTO Sales (Sale_Date, Customer_ID) " + "Values ('" + txtsalesdate.Text + "', '" + txtcustid.Text + "' )");
                 *  cm.Connection = Connectionclass.con;
                 *  cm.ExecuteNonQuery();
                 *  cmd = new SqlCommand("INSERT INTO SalesDetails (Product_ID, Price, Quantity) " + "Values ( '" + txtprodcode.Text + "','" + txtprice.Text + "', '" + txtquantity.Text + "')");
                 *  cmd.Connection = Connectionclass.con;
                 *  cmd.ExecuteNonQuery();
                 *  int lefta = Convert.ToInt32(txtleftitem.Text);
                 *  if (lefta <= 10)
                 *  {
                 *      MessageBox.Show("Please be warned! \nthe product you selected maybe out numbered \nPlease contact Supplier!", "Warning!");
                 *
                 *  }
                 *  MessageBox.Show("Saved Successfully", "Saving");
                 *
                 *
                 *  txtquantity.Text = "";
                 *  txtprodcode.SelectedIndex = -1;
                 *  txtcustid.SelectedIndex = -1;
                 *  txtinfocustname.Clear();
                 *  txtleftitem.Clear();
                 *  txtquantity.Clear();
                 *  txtinfoprod.Clear();
                 *  txtdiscount.Clear();
                 *  txtprice.Clear();
                 *  txtTotal.Text = "0.00";
                 *
                 *
                 *
                 *  //refresh
                 *
                 *  cmd = new SqlCommand("SELECT * from SalesDetails");
                 *  cmd.Connection = Connectionclass.con;
                 *  sda = new SqlDataAdapter(cmd);
                 *  cmb = new SqlCommandBuilder(sda);
                 *  ds = new DataSet();
                 *  sda.Fill(ds, "Sales");
                 *  dt = ds.Tables["Sales"];
                 *
                 *  data.DataSource = ds.Tables["Sales"];
                 *  data.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                 *  DateTime dta = DateTime.Now;
                 *  txtsalesdate.Text = DateTime.Now.ToString();
                 *
                 *
                 * }
                 * catch (Exception ex)
                 * {
                 *  MessageBox.Show(ex.ToString(), "Error");
                 * }
                 * finally
                 * {
                 *  conn.Closecon();
                 * }*/
            }
            //UPDATE SALES
            if (e.KeyData == Keys.F2)
            {
                ////UPDATE
                bool   error  = true;
                bool   error1 = true;
                bool   error2 = true;
                string id     = txtcustid.Text;
                string pcode  = txtprodcode.Text;
                string qty    = txtquantity.Text;
                //Start TXTCustid Constraints
                foreach (char c in id)
                {
                    if (!Char.IsNumber(c))
                    {
                        error = false;
                        break;
                    }
                }

                if (error == false)
                {
                    MessageBox.Show("The Customer ID you entered does'nt exist in the RECORD", "Error");
                    return;
                }
                ///end of txtCUSTID Constraints
                ///
                ///Start of txtprodcode Constraints
                foreach (char c in pcode)
                {
                    if (!Char.IsNumber(c))
                    {
                        error1 = false;
                        break;
                    }
                }

                if (error1 == false)
                {
                    MessageBox.Show("The Product Code you entered does'nt exist in the RECORD", "Error");
                    return;
                }
                ///end of txtprodcode Constraints
                ///
                ///Start of txtquantity Constraints
                foreach (char c in qty)
                {
                    if (!Char.IsNumber(c))
                    {
                        error2 = false;
                        break;
                    }
                }
                if (error2 == false)
                {
                    MessageBox.Show("Invalid Input Please Checked Quantity Field for INCORRECT input", "Error");
                    return;
                }
                ///end of txtquantity Constraints



                if (txtprodcode.Text == "" || txtdiscount.Text == "" || txtprice.Text == "" || txtquantity.Text == "")
                {
                    MessageBox.Show("No Such Record To Update", "Error");
                    return;
                }

                try
                {
                    conn.dbcon();
                    cmb = new SqlCommandBuilder(sda);
                    sda.Update(ds, "Sales");
                    cmd            = new SqlCommand("Update SalesDetails set Product_ID  = '" + txtprodcode.Text + "' , Price = '" + txtprice.Text + "',Quantity = '" + txtquantity.Text + "', Discount = '" + txtdiscount.Text + "'  where Sale_No = '" + txtsaleno.Text + "'");
                    cmd.Connection = Connectionclass.con;
                    cmd.ExecuteNonQuery();
                    cmd            = new SqlCommand("Update Sales set Customer_ID  = '" + txtcustid.Text + "' where Sale_No = '" + txtsaleno.Text + "'");
                    cmd.Connection = Connectionclass.con;
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Successfully Updated", "Update");

                    txtcustid.Enabled = true;
                    ////clear

                    txtquantity.Text          = "";
                    txtprodcode.SelectedIndex = -1;
                    txtcustid.SelectedIndex   = -1;
                    txtinfocustname.Clear();

                    txtquantity.Clear();
                    txtinfoprod.Clear();
                    txtdiscount.Clear();
                    txtprice.Clear();
                    txtTotal.Text        = "0.00";
                    txtquantity.ReadOnly = true;
                    txtdiscount.ReadOnly = true;
                    //refresh

                    cmd            = new SqlCommand("select SD.Sale_No, S.Customer_ID, SD.Product_ID, SD.Price, SD.Quantity , SD.Discount from Sales S inner join SalesDetails SD on S.Sale_No = SD.Sale_No order by SD.Sale_No DESC");
                    cmd.Connection = Connectionclass.con;
                    sda            = new SqlDataAdapter(cmd);
                    cmb            = new SqlCommandBuilder(sda);
                    ds             = new DataSet();
                    sda.Fill(ds, "Sales");
                    dt = ds.Tables["Sales"];
                    data.DataSource    = ds.Tables["Sales"];
                    data.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                    DateTime dta = DateTime.Now;
                    txtsalesdate.Text = DateTime.Now.ToString();
                }
                catch
                {
                }
                finally
                {
                    conn.Closecon();
                    txtcustid.Enabled   = false;
                    txtprodcode.Enabled = false;
                }

                ///product Left
                try
                {
                    conn.dbcon();
                    SqlCommand tot = new SqlCommand("Select sum(Quantity) from stockcard where Product_ID like '" + txtprodcode.Text + "%'");
                    tot.Connection = Connectionclass.con;
                    SqlDataReader DR1 = tot.ExecuteReader();
                    if (DR1.Read())
                    {
                        txtleftitem.Text = DR1.GetValue(0).ToString();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error");
                }
                finally
                {
                    conn.Closecon();
                    txtleftitem.Clear();
                }
            }

            //BACK
            if (e.KeyData == Keys.Escape)
            {
                this.Hide();
                Main display = new Main();
                display.ShowDialog();
                this.Close();
            }
        }
コード例 #3
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.F1)
            {
                this.Hide();
                addcust display = new addcust();
                display.ShowDialog();
            }
            if (e.KeyData == Keys.Escape)
            {
                this.Hide();
                Main display = new Main();
                display.ShowDialog();
                this.Close();
            }
            if (e.KeyData == Keys.Enter || e.KeyData == Keys.F2)
            {
                string a = txtact.Text;

                if (txtcustid.Text == "" || txtname.Text == "" || txtaddress.Text == "" || txtcontact.Text == "")
                {
                    MessageBox.Show("No such Record To Update", "Error");
                    return;
                }
                if (a.Equals("Y") || a.Equals("N") || a.Equals("y") || a.Equals("n") || a.Equals(""))
                {
                    try
                    {
                        conn.dbcon();
                        cmb = new SqlCommandBuilder(sda);
                        sda.Update(ds, "Customer");
                        cmd            = new SqlCommand("Update Customers set CustomerName  = '" + txtname.Text + "' , Address = '" + txtaddress.Text + "',Contact_No = '" + txtcontact.Text + "', Status = '" + txtact.Text + "' where Customer_ID = '" + txtcustid.Text + "'");
                        cmd.Connection = Connectionclass.con;
                        cmd.ExecuteNonQuery();
                        MessageBox.Show("Successfully Updated", "Update");

                        txtcustid.Clear();
                        txtname.Clear();
                        txtaddress.Clear();
                        txtcontact.Clear();
                        txtact.Clear();
                        txtcustid.ReadOnly  = true;
                        txtname.ReadOnly    = true;
                        txtaddress.ReadOnly = true;
                        txtcontact.ReadOnly = true;
                        txtact.ReadOnly     = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "Error");
                    }
                    finally
                    {
                        conn.Closecon();
                    }
                    //////REFRESH!!!REFRESH!!!REFRESH!!!REFRESH!!!REFRESH!!!REFRESH!!!REFRESH!!!
                    try
                    {
                        conn.dbcon();
                        cmd            = new SqlCommand("SELECT * FROM Customers order by Customer_ID DESC");
                        cmd.Connection = Connectionclass.con;
                        sda            = new SqlDataAdapter(cmd);
                        cmb            = new SqlCommandBuilder(sda);
                        ds             = new DataSet();
                        sda.Fill(ds, "Customer");
                        dt = ds.Tables["Customer"];

                        data.DataSource    = ds.Tables["Customer"];
                        data.ReadOnly      = false;
                        data.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "Error");
                    }
                    finally
                    {
                        conn.Closecon();
                    }
                }
                else
                {
                    MessageBox.Show("Y or N input Only; Y stands for Yes and N stands for No", "Error");
                    return;
                }
            }
        }
コード例 #4
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            //add orders
            if (e.KeyData == Keys.F1)
            {
                this.Hide();
                addporder disply = new addporder();
                disply.ShowDialog();

                /* if (combosupid.Text == "" || txtprodid.Text == "" || txtqty.Text == "" || txtTotal.Text == "")
                 * {
                 *   MessageBox.Show("All fields cannot be empty", "Error");
                 *   return;
                 * }
                 *
                 * try
                 * {
                 *   conn.dbcon();
                 *   SqlCommand cm = new SqlCommand("INSERT INTO Orders (Order_Date, Supplier_ID) " + "Values ('" + txtordersdate.Text + "', '" + combosupid.Text + "' )");
                 *   cm.Connection = Connectionclass.con;
                 *   cm.ExecuteNonQuery();
                 *   cmd = new SqlCommand("INSERT INTO OrderDetails (Product_ID, Cost, Quantity) " + "Values ('" + txtprodid.Text + "', '" + txtcost.Text + "' , '" + txtqty.Text + "')");
                 *   cmd.Connection = Connectionclass.con;
                 *   cmd.ExecuteNonQuery();
                 *   MessageBox.Show("Saved Successfully", "Saving");
                 *
                 *   ///clear
                 *
                 *   txtqty.Text = "";
                 *   txtprodid.SelectedIndex = -1;
                 *   combosupid.SelectedIndex = -1;
                 *   txtsupname.Clear();
                 *   txtprodname.Clear();
                 *   txtunitmeas.Clear();
                 *   txtTotal.Text = "0.00";
                 *
                 *   ///refresh
                 *   cmd = new SqlCommand("Select * from OrderDetails");
                 *   cmd.Connection = Connectionclass.con;
                 *   sda = new SqlDataAdapter(cmd);
                 *   cmb = new SqlCommandBuilder(sda);
                 *   ds = new DataSet();
                 *   sda.Fill(ds, "OrderDt");
                 *   dt = ds.Tables["OrderDt"];
                 *
                 *   data.DataSource = ds.Tables["OrderDt"];
                 *   data.ReadOnly = false;
                 *   data.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                 *   txtTotal.ReadOnly = true;
                 *   txtordersdate.ReadOnly = true;
                 *
                 *
                 * }
                 * catch (Exception ex)
                 * {
                 *   MessageBox.Show(ex.ToString(), "Error");
                 * }
                 * finally
                 * {
                 *   conn.Closecon();
                 *   txtcost.Clear();
                 * }*/
            }
            ///update

            if (e.KeyData == Keys.Enter || e.KeyData == Keys.F2)
            {
                ////UPDATE
                bool   error  = true;
                bool   error1 = true;
                bool   error2 = true;
                string id     = combosupid.Text;
                string pcode  = txtprodid.Text;
                string qty    = txtqty.Text;
                //Start TXTCustid Constraints
                foreach (char c in id)
                {
                    if (!Char.IsNumber(c))
                    {
                        error = false;
                        break;
                    }
                }

                if (error == false)
                {
                    MessageBox.Show("The Supplier ID you entered does not exist in the RECORD", "Error");
                    return;
                }
                ///end of txtCUSTID Constraints
                ///
                ///Start of txtprodcode Constraints
                foreach (char c in pcode)
                {
                    if (!Char.IsNumber(c))
                    {
                        error1 = false;
                        break;
                    }
                }

                if (error1 == false)
                {
                    MessageBox.Show("The Product Code you entered does not exist in the RECORD", "Error");
                    return;
                }
                ///end of txtprodcode Constraints
                ///
                ///Start of txtquantity Constraints
                foreach (char c in qty)
                {
                    if (!Char.IsNumber(c))
                    {
                        error2 = false;
                        break;
                    }
                }
                if (error2 == false)
                {
                    MessageBox.Show("Invalid Input Please Checked Quantity Field for INCORRECT input", "Error");
                    return;
                }
                ///end of txtquantity Constraints



                if (txtprodid.Text == "" || txtqty.Text == "" || txtTotal.Text == "")
                {
                    MessageBox.Show("No such Record To Update", "Error");
                    return;
                }
                try
                {
                    conn.dbcon();
                    cmb = new SqlCommandBuilder(sda);
                    sda.Update(ds, "OrderDt");
                    cmd            = new SqlCommand("Update OrderDetails set Product_ID  = '" + txtprodid.Text + "' , Cost = '" + txtcost.Text + "', Quantity = '" + txtqty.Text + "' where Order_No = '" + txtorderno.Text + "'");
                    cmd.Connection = Connectionclass.con;
                    cmd.ExecuteNonQuery();
                    cmd            = new SqlCommand("Update Orders set Supplier_ID  = '" + combosupid.Text + "' where Order_No = '" + txtorderno.Text + "'");
                    cmd.Connection = Connectionclass.con;
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Successfully Updated", "Update");

                    ///clear
                    combosupid.SelectedIndex = -1;
                    txtprodid.SelectedIndex  = -1;
                    txtprodname.Clear();
                    txtsupname.Clear();
                    txtunitmeas.Clear();
                    txtcost.Clear();
                    txtqty.Clear();
                    txtTotal.Text      = "0.00";
                    combosupid.Enabled = false;
                    txtprodid.Enabled  = false;
                    txtqty.ReadOnly    = true;

                    //refresh

                    cmd            = new SqlCommand("select OD.Order_No, O.Supplier_ID, OD.Product_ID, OD.Cost, OD.Quantity from Orders O inner join OrderDetails OD on O.Order_No = OD.Order_No order by OD.Order_No DESC");
                    cmd.Connection = Connectionclass.con;
                    sda            = new SqlDataAdapter(cmd);
                    cmb            = new SqlCommandBuilder(sda);
                    ds             = new DataSet();
                    sda.Fill(ds, "OrderDt");
                    dt = ds.Tables["OrderDt"];

                    data.DataSource        = ds.Tables["OrderDt"];
                    data.ReadOnly          = false;
                    data.SelectionMode     = DataGridViewSelectionMode.FullRowSelect;
                    txtTotal.ReadOnly      = true;
                    txtordersdate.ReadOnly = true;
                    ComputeAdd.Enabled     = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error");
                }
                finally
                {
                    conn.Closecon();
                }
            }
            //back
            if (e.KeyData == Keys.Escape)
            {
                this.Hide();
                Main display = new Main();
                display.ShowDialog();
                this.Close();
            }

            //add product or items
            if (e.KeyData == Keys.F3)
            {
                this.Hide();
                Item display = new Item();
                display.ShowDialog();
            }
        }
コード例 #5
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.F1)
            {
                //Add Supplier
                this.Hide();
                AddingSupplier display = new AddingSupplier();
                display.ShowDialog();
            }
            if (e.KeyData == Keys.F2)
            {
                //Update
                string a = txtact.Text;

                if (txtsupname.Text == "" || txtaddress.Text == "" || txttel.Text == "")
                {
                    MessageBox.Show("No such Record to Update", "Error");
                    return;
                }

                if (a.Equals("Y") || a.Equals("N") || a.Equals("y") || a.Equals("n") || a.Equals(""))
                {
                    try
                    {
                        conn.dbcon();
                        cmb = new SqlCommandBuilder(sda);
                        sda.Update(ds, "Supplier");
                        cmd            = new SqlCommand("Update Suppliers set Supplier_Name  = '" + txtsupname.Text + "' , Address = '" + txtaddress.Text + "', Telephone_No = '" + txttel.Text + "', Status = '" + txtact.Text + "' where Supplier_ID = '" + txtcustid.Text + "'");
                        cmd.Connection = Connectionclass.con;
                        cmd.ExecuteNonQuery();
                        MessageBox.Show("Successfully Updated", "Update");
                        //clear
                        txtsupname.Clear();
                        txtaddress.Clear();
                        txttel.Clear();
                        txtact.Clear();
                        txtsupname.ReadOnly = true;
                        txtaddress.ReadOnly = true;
                        txttel.ReadOnly     = true;
                        txtcustid.Clear();
                        txtact.ReadOnly = true;



                        //refresh

                        cmd            = new SqlCommand("SELECT * FROM Suppliers");
                        cmd.Connection = Connectionclass.con;
                        sda            = new SqlDataAdapter(cmd);
                        cmb            = new SqlCommandBuilder(sda);
                        ds             = new DataSet();
                        sda.Fill(ds, "Supplier");
                        dt = ds.Tables["Supplier"];

                        data.DataSource    = ds.Tables["Supplier"];
                        data.ReadOnly      = false;
                        data.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "Error");
                    }
                    finally
                    {
                        conn.Closecon();
                    }
                }

                else
                {
                    MessageBox.Show("Y or N input Only; Y stands for Yes and N stands for No", "Error");
                    return;
                }
            }
            if (e.KeyData == Keys.Escape)
            {
                this.Hide();
                Main display = new Main();
                display.ShowDialog();
                this.Close();
            }
        }