예제 #1
0
        private void add_Click(object sender, EventArgs e)
        {
            {
                if (cases == 1)
                {
                    try
                    {
                        if (id_txt.Text.Length > 0 && bank_txt.Text.Length > 0 && owner_txt.Text.Length > 0 &&
                            price_txt.Text.Length > 0)
                        {
                            string      id     = id_txt.Text;
                            double      price  = Convert.ToDouble(price_txt.Text);
                            Check_Class checks = new Check_Class(id, bank_txt.Text, owner_txt.Text, date_pic.Value, price, note_combo.SelectedItem.ToString(), img);
                            payment.SetCheck(checks);
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("يجب ملئ جميع الخانات");
                        }
                    }
                    catch (FormatException)
                    {
                        MessageBox.Show("لقد ادخلت قيمه خاظئه");
                    }
                }
                else if (cases == 2)
                {
                    try
                    {
                        if (id_txt.Text.Length > 0 && bank_txt.Text.Length > 0 && owner_txt.Text.Length > 0 &&
                            price_txt.Text.Length > 0)
                        {
                            string id    = id_txt.Text;
                            double price = Convert.ToDouble(price_txt.Text);
                            if (img == null)
                            {
                                string query = "INSERT INTO checks (ch_id,bill_id,ch_bank,ch_owner,ch_date,ch_price,ch_notes) VALUES('" + id + "','" + Payment_id + "' ,'" + bank_txt.Text + "'" +
                                               ",'" + owner_txt.Text + "','" + FormatDate(date_pic.Value) + "' ," + price + " ,'" + note_combo.SelectedItem + "')";
                                if (db.insertDB(query))
                                {
                                    MessageBox.Show("تم اضافه الشيك");
                                    form2.RefreshCheck();
                                    this.Close();
                                }
                            }
                            else
                            {
                                string query = "INSERT INTO checks  VALUES('" + id + "','" + Payment_id + "' ,'" + bank_txt.Text + "'" +
                                               ",'" + owner_txt.Text + "','" + FormatDate(date_pic.Value) + "' ," + price + " ,'" + note_combo.SelectedItem + "',@picture)";

                                Thread th = new Thread(() =>
                                {
                                    if (InvokeRequired)
                                    {
                                        this.Invoke(new MethodInvoker(delegate
                                        {
                                            if (db.insertImg(query, img))
                                            {
                                                MessageBox.Show("تم اضافه الشيك");
                                                form2.RefreshCheck();
                                                this.Close();
                                            }
                                        }));
                                    }
                                });
                                th.Start();
                            }
                        }
                        else
                        {
                            MessageBox.Show("يجب ملئ جميع الخانات");
                        }
                    }
                    catch (FormatException)
                    {
                        MessageBox.Show("لقد ادخلت قيمه خاظئه");
                    }
                }
                else if (cases == 3)
                {
                    try
                    {
                        if (id_txt.Text.Length > 0 && bank_txt.Text.Length > 0 && owner_txt.Text.Length > 0 &&
                            price_txt.Text.Length > 0)
                        {
                            int    id    = Convert.ToInt32(id_txt.Text);
                            double price = Convert.ToDouble(price_txt.Text);
                            string query = "UPDATE checks SET ch_bank='" + bank_txt.Text + "'" +
                                           ",ch_owner='" + owner_txt.Text + "',ch_date='" + FormatDate(date_pic.Value) + "' ,ch_price=" + price + " ,ch_notes='" + note_combo.SelectedItem + "' WHERE ch_id=" + ch_id;
                            if (db.updateDB(query))
                            {
                                this.Close();
                                form2.RefreshCheck();
                            }
                        }
                        else
                        {
                            MessageBox.Show("يجب ملئ جميع الخانات");
                        }
                    }
                    catch (FormatException)
                    {
                        MessageBox.Show("لقد ادخلت قيمه خاظئه");
                    }
                }
            }
        }
예제 #2
0
        private void save_Click(object sender, EventArgs e)
        {
            if (cases == 1)
            {
                try
                {
                    int    id            = Convert.ToInt32(id_txt.Text);
                    string cust_type     = cust_type_combo.SelectedItem.ToString();
                    string cust_name     = customer_combo.SelectedItem.ToString();
                    int    teethes_count = Convert.ToInt32(teethes_txt.Text);
                    string color         = color_combo.SelectedItem.ToString();;
                    string type          = type_combo.SelectedItem.ToString();
                    string delv_state    = delv_state_combo.SelectedItem.ToString();
                    price = Convert.ToDouble(price_txt.Text);


                    DateTime rec_date  = DateTime.Today;
                    DateTime delv_date = DateTime.Today;
                    if (delv_state == "لم يسلم")
                    {
                        delv_date = new DateTime();
                    }
                    string notes = notes_txt.Text;
                    if (cust_type != "" && cust_name != "" && teethes_count > 0 && color != "" && type != "" && notes != "")
                    {
                        string id_select = "SELECT cust_id from customer where cust_name='" + cust_name + "'";


                        string insert_query2 = "INSERT INTO bill (bill_id,cust_id,bill_teethes,bill_color,bill_type,bill_delv_state,bill_rec_date,bill_delv_date,bill_price,bill_notes,user_id) VALUES('" + id + "' ,'" + db.SelectID(id_select) + "' ,'" + teethes_count +
                                               "','" + color + "','" + type + "','" + delv_state + "','" + FormatDate(rec_date) + "' ,'" + FormatDate(delv_date) + "' ,'" + price + "' , '" + notes + "','" + form.Id + "')";

                        string select_id = "SELECT * from bill WHERE bill_id='" + id + "' AND year(bill_rec_date)='" + rec_date.Year + "'";
                        if (!db.DoseExists(select_id))
                        {
                            if (db.insertDB(insert_query2))
                            {
                                int TheId = Convert.ToInt32(db.ListOF("SELECT MAX(id) from bill").Last());
                                if (type != "مثبت" && type != "حارس ليلي")
                                {
                                    for (int x = 0; x < teethes_list.Length; x++)
                                    {
                                        if (teethes_list[x])
                                        {
                                            string query = "INSERT INTO teeth VALUES('" + x + "','" + TheId + "')";
                                            db.insertDB(query);
                                        }
                                    }
                                }
                                if (warr_years > 0)
                                {
                                    string query = "INSERT INTO warrnity (warr_patient,bill_id,warr_years) VALUES('" + patient + "','" + TheId + "','" + warr_years + "')";
                                    db.insertDB(query);
                                }
                                MessageBox.Show("تم اضافه الفاتوره");
                                this.Close();
                                form.RefreshBill(form.bill_query);
                                if (MessageBox.Show("هل تريد عرض الفاتوره", "تفاصيل الفاتوره", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    new ShowBill(TheId, form.Id).Show();
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("هذه الفاتوره موجوده");
                        }
                    }
                    else
                    {
                        MessageBox.Show("تاكد من ادخال جميع القيم بشكل صحيح");
                    }
                }
                catch (FormatException)
                {
                    MessageBox.Show("لقد ادخلت ارقام خاطئه");
                }
            }
            else if (cases == 2)
            {
                try
                {
                    int      id            = Convert.ToInt32(id_txt.Text);
                    string   cust_type     = cust_type_combo.SelectedItem.ToString();
                    string   cust_name     = customer_combo.SelectedItem.ToString();
                    int      teethes_count = Convert.ToInt32(teethes_txt.Text);
                    string   color         = color_combo.SelectedItem.ToString();
                    string   type          = type_combo.SelectedItem.ToString();
                    string   delv_state    = delv_state_combo.SelectedItem.ToString();
                    double   price         = Convert.ToDouble(price_txt.Text);
                    DateTime delv_date     = DateTime.Today;
                    if (delv_state == "لم يسلم")
                    {
                        delv_date = new DateTime();
                    }
                    string notes = notes_txt.Text;
                    if (cust_type != "" && cust_name != "" && teethes_count > 0 && color != "" && type != "" && notes != "")
                    {
                        string update_query = "UPDATE bill set bill_id='" + id + "',cust_id=(SELECT cust_id from customer where cust_name='" + cust_name + "'),bill_teethes='" + teethes_count + "',bill_color='" + color + "',bill_type='" + type + "',bill_delv_state='" + delv_state + "',bill_delv_date='" + FormatDate(delv_date) + "',bill_price='" + price + "',bill_notes='" + notes + "' WHERE id='" + bill_id + "'";
                        if (db.updateDB(update_query))
                        {
                            db.deleteDB("delete from teeth where bill_id='" + bill_id + "'");
                            if (type != "مثبت" && type != "حارس ليلي")
                            {
                                for (int x = 0; x < teethes_list.Length; x++)
                                {
                                    if (teethes_list[x])
                                    {
                                        string query = "INSERT INTO teeth VALUES('" + x + "','" + bill_id + "')";
                                        db.insertDB(query);
                                    }
                                }
                            }
                            MessageBox.Show("تم تعديل الفاتوره");
                            form2.RefreshTheBill();
                            this.Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show("تاكد من ادخال جميع القيم بشكل صحيح");
                    }
                }
                catch (FormatException)
                {
                    MessageBox.Show("لقد ادخلت ارقام خاطئه");
                }
            }
        }