Beispiel #1
0
 public Home()
 {
     InitializeComponent();
     Db = new DTDB();
 }
Beispiel #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            int c = 0, c1 = 0;

            if (string.IsNullOrWhiteSpace(txtCode.Text) || string.IsNullOrWhiteSpace(txtName.Text) || (txtML.Visible == true && string.IsNullOrWhiteSpace(txtML.Text)) || string.IsNullOrWhiteSpace(txtAc.Text) || string.IsNullOrWhiteSpace(txtFc.Text) || string.IsNullOrWhiteSpace(txtGarden.Text) || string.IsNullOrWhiteSpace(txtOc.Text) || string.IsNullOrWhiteSpace(txtParcel.Text) || string.IsNullOrWhiteSpace(txtRoom.Text))
            {
                MessageBox.Show("Please fill all the feilds");
                return;
            }
            if (comboGroup.SelectedIndex < 0 || (comboSubGroup.Visible == true && comboSubGroup.SelectedIndex < 0))
            {
                MessageBox.Show("Please Select Product category or subcategory");
                return;
            }
            try
            {
                db = new DTDB();

                String        sql = "insert into " + DTDB.TABLE_ITEMS + " (code,name,ml,category,tax,fc,ac,oc,room,parcel,garden) values(@code,@name,@ml,@category,@tax,@fc,@ac,@oc,@room,@parcel,@garden)";
                SQLiteCommand cmd = new SQLiteCommand(sql, db.conn);
                cmd.Parameters.Add("@code", DbType.Int32).Value  = txtCode.Text;
                cmd.Parameters.Add("@name", DbType.String).Value = txtName.Text;
                if (comboSubGroup.Visible == true)
                {
                    if (comboSubGroup.Text.ToUpper().Contains("LIQUOR"))
                    {
                        cmd.Parameters.Add("@ml", DbType.Int32).Value = txtML.Text;
                    }
                    else
                    {
                        cmd.Parameters.Add("@ml", DbType.Int32).Value = 0;
                    }

                    cmd.Parameters.Add("@category", DbType.String).Value = comboSubGroup.Text;
                }
                else
                {
                    cmd.Parameters.Add("@ml", DbType.Int32).Value        = 0;
                    cmd.Parameters.Add("@category", DbType.String).Value = comboGroup.Text;
                }
                if (chkTax.Checked == true)
                {
                    cmd.Parameters.Add("@tax", DbType.Int32).Value = 1;
                }
                else
                {
                    cmd.Parameters.Add("@tax", DbType.Int32).Value = 0;
                }
                cmd.Parameters.Add("@fc", DbType.Double).Value     = txtFc.Text;
                cmd.Parameters.Add("@ac", DbType.Double).Value     = txtAc.Text;
                cmd.Parameters.Add("@oc", DbType.Double).Value     = txtOc.Text;
                cmd.Parameters.Add("@room", DbType.Double).Value   = txtFc.Text;
                cmd.Parameters.Add("@parcel", DbType.Double).Value = txtParcel.Text;
                cmd.Parameters.Add("@garden", DbType.Double).Value = txtGarden.Text;
                sql = "insert into " + DTDB.TABLE_STOCK + " (code,qty,ml) values(@code,@qty,@ml)";

                SQLiteCommand cmd1 = new SQLiteCommand(sql, db.conn);
                cmd1.Parameters.Add("@code", DbType.Int32).Value = txtCode.Text;
                cmd1.Parameters.Add("@qty", DbType.Int32).Value  = txtQty.Text;
                if (comboSubGroup.Visible == true && comboSubGroup.Text.ToUpper().Contains("LIQUOR"))
                {
                    cmd1.Parameters.Add("@ml", DbType.Int32).Value = txtML.Text;
                }
                else
                {
                    cmd1.Parameters.Add("@ml", DbType.Int32).Value = 0;
                }
                if ((c = cmd.ExecuteNonQuery()) > 0 && (c1 = cmd1.ExecuteNonQuery()) > 0)
                {
                    MessageBox.Show("Item Added SuccessFully");
                }
                else if (c > 0 && c1 <= 0)
                {
                    SQLiteCommand cmd2 = new SQLiteCommand("delete from " + DTDB.TABLE_ITEMS + " where code=@code", db.conn);
                    cmd2.Parameters.Add("@code", DbType.Int32).Value = txtCode.Text;
                    cmd2.ExecuteNonQuery();
                    MessageBox.Show("Unable to Add the Product Please try again later...");
                }
                else if (c <= 0 && c1 > 0)
                {
                    SQLiteCommand cmd2 = new SQLiteCommand("delete from " + DTDB.TABLE_STOCK + " where code=@code", db.conn);
                    cmd2.Parameters.Add("@code", DbType.Int32).Value = txtCode.Text;
                    cmd2.ExecuteNonQuery();
                    MessageBox.Show("Unable to Add the Product Please try again later...");
                }
            }
            catch (SQLiteException e1)
            {
                if (e1.ErrorCode == 19)
                {
                    MessageBox.Show("Item With such code already exists!!! ");
                }
                else
                {
                    MessageBox.Show(e1.Message);
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
            }
            finally
            {
                db.conn.Close();
            }
        }