示例#1
0
        public Form_ApproveExpense(Form1 form, DBinterface dbInterface, List <string> id)
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new System.Globalization.CultureInfo("en-US"));
            localInterface = dbInterface;
            mainForm       = form;
            this.ids       = id;
            DataTable dt = localInterface.Select("SELECT approved,date,amount FROM expenses WHERE id=" + ids[0]).Tables[0];

            approved = (bool)dt.Rows[0][0];
            comboBox1.SelectedIndex = 0;
            if (approved)
            {
                comboBox1.SelectedIndex = 1;
            }
            date = MyUtills.dateFromSQL(dt.Rows[0][1].ToString());
            dateTimePicker1.Value = date;
            if (this.ids.Count > 1)
            {
                checkBoxDate.Checked = false;
                textBox1.Visible     = false;
                label1.Visible       = false;
            }
            else
            {
                textBox1.Text = String.Format("{0:0,0.00}", double.Parse(dt.Rows[0][2].ToString()));
            }
        }
        private void buttonUserEnter_Click(object sender, EventArgs e)
        {
            string username = textBoxUsername.Text;
            string pass     = textBoxPassword.Text;

            if (username == String.Empty || pass == String.Empty)
            {
                return;
            }

            pass = MyUtills.ConvertToMd5(pass);

            string adminUsername = "******";
            string adminPassword = MyUtills.ConvertToMd5("bnrbnr");

            DataTable userTable = localInterface.Select("SELECT type FROM users WHERE username='******' AND password='******'").Tables[0];
            int       res       = userTable.Rows.Count;

            if (username == adminUsername && pass == adminPassword)
            {
                mainForm.UserEnter(1);
                this.Close();
            }
            else if (res > 0)
            {
                mainForm.UserEnter((int)userTable.Rows[0][0]);
                this.Close();
            }
            else
            {
                labelStatus.Text      = "שם משתמש או סיסמא לא נכונים";
                labelStatus.ForeColor = Color.Red;
            }
        }
示例#3
0
        private void buttonYes_Click(object sender, EventArgs e)
        {
            string app = comboBox1.SelectedIndex.ToString();

            if (ids.Count > 1)
            {
                foreach (string id in ids)
                {
                    if (checkBoxDate.Checked)
                    {
                        if (checkBoxPaiment.Checked)
                        {
                            localInterface.Update("UPDATE expenses SET date='" + MyUtills.dateToSQL(dateTimePicker1.Value) + "',approved='" + app + "' WHERE id=" + id);
                        }
                        else
                        {
                            localInterface.Update("UPDATE expenses SET date='" + MyUtills.dateToSQL(dateTimePicker1.Value) + "' WHERE id=" + id);
                        }
                    }
                    else
                    {
                        if (checkBoxPaiment.Checked)
                        {
                            localInterface.Update("UPDATE expenses SET approved='" + app + "' WHERE id=" + id);
                        }
                    }
                }
            }
            else
            {
                string amount = textBox1.Text.Replace(",", "");
                if (checkBoxDate.Checked)
                {
                    if (checkBoxPaiment.Checked)
                    {
                        localInterface.Update("UPDATE expenses SET date='" + MyUtills.dateToSQL(dateTimePicker1.Value) + "',approved='" + app + "',amount='" + amount + "' WHERE id=" + ids[0]);
                    }
                    else
                    {
                        localInterface.Update("UPDATE expenses SET date='" + MyUtills.dateToSQL(dateTimePicker1.Value) + "',amount='" + amount + "' WHERE id=" + ids[0]);
                    }
                }
                else
                {
                    localInterface.Update("UPDATE expenses SET approved='" + app + "',amount='" + amount + "' WHERE id=" + ids[0]);
                }
            }
            this.Close();
            mainForm.showFinance();
        }
示例#4
0
        private void buttonYes_Click(object sender, EventArgs e)
        {
            DateTime newDate = dateTimePicker1.Value;

            if (this.definite)
            {
                localInterface.Update("UPDATE bills SET payDate='" + MyUtills.dateToSQL(newDate) + "' WHERE id=" + this.id);
            }
            else
            {
                localInterface.Update("UPDATE bills SET toPayDate='" + MyUtills.dateToSQL(newDate) + "' WHERE id=" + this.id);
            }
            this.Close();
            mainForm.showFinance();
        }
        private void buttonAddUser_Click(object sender, EventArgs e)
        {
            if (textBoxNewUsername.Text == String.Empty || textBoxNewPassword.Text == String.Empty)
            {
                return;
            }

            string pass = MyUtills.ConvertToMd5(textBoxNewPassword.Text);

            bool res = localInterface.InsertSql("INSERT INTO users (username,password,type) VALUES ('" + textBoxNewUsername.Text + "','" + pass + "','" + comboBoxUserTypes.SelectedValue + "')");

            if (res == true)
            {
                showUsers();
            }
        }
示例#6
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (textBoxText.Text == String.Empty)
            {
                labelText.ForeColor = Color.Red;
                return;
            }
            textBoxText.Text = textBoxText.Text.Replace(@"\", @"\\").Replace("'", @"\'").Replace('"', '\"');
            string date = MyUtills.dateToSQL(DateTime.Now) + " " + DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString();

            localInterface.Insert("notes", "idBill,name,date,text", idBill + "','" +
                                  textBoxName.Text + "','" +
                                  date + "','" +
                                  textBoxText.Text);
            MessageBox.Show("הודעת מעקב חדשה נשמרה במערכת", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
            mainForm.refreshBillNotes(idBill);
            this.Close();
        }
示例#7
0
        public Form_EditIncome(Form1 form, DBinterface dbInterface, string id, bool def)
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new System.Globalization.CultureInfo("en-US"));
            localInterface = dbInterface;
            mainForm       = form;
            this.id        = id;
            this.definite  = def;

            if (definite)
            {
                dateTimePicker1.Value = MyUtills.dateFromSQL(localInterface.Select("SELECT payDate FROM bills WHERE id=" + this.id).Tables[0].Rows[0][0].ToString());
            }
            else
            {
                dateTimePicker1.Value = MyUtills.dateFromSQL(localInterface.Select("SELECT toPayDate FROM bills WHERE id=" + this.id).Tables[0].Rows[0][0].ToString());
            }
        }
        private void labelUpdateVat_Click(object sender, EventArgs e)
        {
            DataTable dt          = new DataTable();
            double    newVat      = 0;
            string    inputNewVat = textBoxNewVat.Text;

            if (inputNewVat == "")
            {
                inputNewVat = "0";
            }
            if (!Double.TryParse(inputNewVat, out newVat))
            {
                MessageBox.Show("מע\"מ לא חוקי", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
                return;
            }
            String newDateFormatted = MyUtills.dateToSQL(dateTimePickerNewVat.Value);

            //String newDate = dateTimePickerNewVat.Value.ToShortDateString();
            //String newDateFormatted = newDate.Substring(6,4) + "-" + newDate.Substring(3,2) + "-" + newDate.Substring(0,2);
            dt = localInterface.Select("SELECT id FROM vat WHERE date='" + newDateFormatted + "'").Tables[0];
            if (dt.Rows.Count > 0)
            {
                if (inputNewVat != "0")
                {
                    localInterface.Update("UPDATE vat SET vat='" + inputNewVat + "' WHERE date='" + newDateFormatted + "'");
                }
                else
                {
                    localInterface.Update("DELETE FROM vat WHERE date='" + newDateFormatted + "'");
                }
            }
            else
            {
                if (inputNewVat != "0")
                {
                    localInterface.Insert("vat", "date,vat", newDateFormatted + "','" + newVat);
                }
            }
            showVatDataGridView();
        }
        private void buttonManageUsers_Click(object sender, EventArgs e)
        {
            string username = textBoxAdminUsername.Text;
            string pass     = textBoxAdminPassword.Text;

            if (username == String.Empty || pass == String.Empty)
            {
                return;
            }

            pass = MyUtills.ConvertToMd5(pass);

            string adminUsername = "******";
            string adminPassword = MyUtills.ConvertToMd5("bnrbnr");

            int res = (int)localInterface.Select("SELECT id FROM users WHERE username='******' AND password='******' AND type=1").Tables[0].Rows.Count;

            if (res > 0 || (username == adminUsername && pass == adminPassword))
            {
                panelUsers.Visible = true;
                showUsers();
                fillUserTypes();
            }
        }
示例#10
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            string query;

            if (radioButtonSingle.Checked)
            {
                double amount;
                if (!Double.TryParse(textBoxAmountSingle.Text, out amount))
                {
                    return;
                }
                DataTable dt = localInterface.Select("SELECT id FROM expenses WHERE idSupplier='" + comboBoxSuppliers.SelectedValue.ToString() + "' AND date='" + MyUtills.dateToSQL(dateTimePickerSingle.Value) + "' AND amount='" + amount.ToString() + "'").Tables[0];
                if (dt.Rows.Count > 0)
                {
                    MessageBox.Show("תשלום זהה קיים כבר", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, MessageBoxOptions.RtlReading);
                    return;
                }
                query = "INSERT INTO expenses (date,amount,idSupplier,type,notes) VALUES ('" + MyUtills.dateToSQL(dateTimePickerSingle.Value) + "','" + amount.ToString() + "','" + comboBoxSuppliers.SelectedValue.ToString() + "','1','" + textBoxNotesSingle.Text + "')";
                localInterface.InsertSql(query);
            }
            else if (radioButtonDebit.Checked)
            {
                double amount;
                if (!Double.TryParse(textBoxAmountDebit.Text, out amount))
                {
                    return;
                }
                int interval = 0;
                switch (comboBoxDebitInterval.SelectedIndex)
                {
                case 0:
                    interval = 1;
                    break;

                case 1:
                    interval = 2;
                    break;

                case 2:
                    interval = 3;
                    break;

                case 3:
                    interval = 6;
                    break;

                case 4:
                    interval = 12;
                    break;
                }
                int duration = 0;
                switch (comboBoxDebitDuration.SelectedIndex)
                {
                case 0:
                    duration = 3;
                    break;

                case 1:
                    duration = 6;
                    break;

                case 2:
                    duration = 12;
                    break;

                case 3:
                    duration = 24;
                    break;

                case 4:
                    duration = 36;
                    break;

                case 5:
                    duration = 60;
                    break;
                }
                if (interval > duration)
                {
                    MessageBox.Show("משך התקופה חייב להיות גדול מזמן החזרה", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, MessageBoxOptions.RtlReading);
                    return;
                }
                DateTime  newdate;
                DataTable newdt;
                for (int i = 0; i < duration; i += interval)
                {
                    newdate = dateTimePickerDebit.Value.AddMonths(i);
                    newdt   = localInterface.Select("SELECT id FROM expenses WHERE idSupplier='" + comboBoxSuppliers.SelectedValue.ToString() + "' AND date='" + MyUtills.dateToSQL(newdate) + "' AND amount='" + amount.ToString() + "'").Tables[0];
                    if (newdt.Rows.Count > 0)
                    {
                        MessageBox.Show("אחד או יותר מהתשלומים כבר קיימים", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, MessageBoxOptions.RtlReading);
                        return;
                    }
                }
                for (int i = 0; i < duration; i += interval)
                {
                    newdate = dateTimePickerDebit.Value.AddMonths(i);
                    query   = "INSERT INTO expenses (date,amount,idsupplier,approved,type,notes) VALUES ('" + MyUtills.dateToSQL(newdate) + "','" + amount + "','" + comboBoxSuppliers.SelectedValue.ToString() + "',1,3,'" + newdate.ToString("MMMM") + "')";
                    localInterface.InsertSql(query);
                }
            }
            else if (radioButtonConst.Checked)
            {
                double amount;
                if (!Double.TryParse(textBoxAmountDebit.Text, out amount))
                {
                    return;
                }
                int interval = 0;
                switch (comboBoxDebitInterval.SelectedIndex)
                {
                case 0:
                    interval = 1;
                    break;

                case 1:
                    interval = 2;
                    break;

                case 2:
                    interval = 3;
                    break;

                case 3:
                    interval = 6;
                    break;

                case 4:
                    interval = 12;
                    break;
                }
                int duration = 0;
                switch (comboBoxDebitDuration.SelectedIndex)
                {
                case 0:
                    duration = 3;
                    break;

                case 1:
                    duration = 6;
                    break;

                case 2:
                    duration = 12;
                    break;

                case 3:
                    duration = 24;
                    break;

                case 4:
                    duration = 36;
                    break;

                case 5:
                    duration = 60;
                    break;
                }
                if (interval > duration)
                {
                    MessageBox.Show("משך התקופה חייב להיות גדול מזמן החזרה", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, MessageBoxOptions.RtlReading);
                    return;
                }
                DateTime  newdate;
                DataTable newdt;
                for (int i = 0; i < duration; i += interval)
                {
                    newdate = dateTimePickerDebit.Value.AddMonths(i);
                    newdt   = localInterface.Select("SELECT id FROM expenses WHERE idSupplier='" + comboBoxSuppliers.SelectedValue.ToString() + "' AND date='" + MyUtills.dateToSQL(newdate) + "' AND amount='" + amount.ToString() + "'").Tables[0];
                    if (newdt.Rows.Count > 0)
                    {
                        MessageBox.Show("אחד או יותר מהתשלומים כבר קיימים", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, MessageBoxOptions.RtlReading);
                        return;
                    }
                }
                for (int i = 0; i < duration; i += interval)
                {
                    newdate = dateTimePickerDebit.Value.AddMonths(i);
                    localInterface.InsertSql("INSERT INTO expenses (date,amount,idsupplier,approved,type,notes) VALUES ('" + MyUtills.dateToSQL(newdate) + "','" + amount + "','" + comboBoxSuppliers.SelectedValue.ToString() + "',0,2,'" + newdate.ToString("MMMM") + "')");
                }
            }
            showExpenses();
        }
示例#11
0
        private void dataGridViewExpenses_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            double   amount;
            DateTime date;
            int      approved = 0;

            if (!DateTime.TryParse(dataGridViewExpenses.Rows[e.RowIndex].Cells[2].Value.ToString(), out date))
            {
                return;
            }
            if (!Double.TryParse(dataGridViewExpenses.Rows[e.RowIndex].Cells[3].Value.ToString(), out amount))
            {
                return;
            }
            if ((bool)dataGridViewExpenses.Rows[e.RowIndex].Cells[4].Value)
            {
                approved = 1;
            }
            localInterface.Update("UPDATE expenses SET amount='" + amount + "', date='" + MyUtills.dateToSQL(date) + "',approved='" + approved.ToString() + "',notes='" + dataGridViewExpenses.Rows[e.RowIndex].Cells[0].Value.ToString() + "' WHERE id='" + dataGridViewExpenses.Rows[e.RowIndex].Cells[1].Value.ToString() + "'");
            //showExpenses(Convert.ToInt16(comboBoxSuppliers.SelectedValue));
            //this.BeginInvoke(new MethodInvoker(showExpenses));
        }
        private void buttonSave_Click(object sender, EventArgs e)
        {
            labelName.ForeColor          = Color.Black;
            labelProjectNumber.ForeColor = Color.Black;
            labelCustomerName.ForeColor  = Color.Black;
            labelAmount.ForeColor        = Color.Black;
            labelPriceIndex.ForeColor    = Color.Black;

            bool returnFlag = false;

            if (textBoxDetailsProjectName.Text == String.Empty)
            {
                labelName.ForeColor = Color.Red;
                returnFlag          = true;
            }
            if (textBoxDetailsProjectNumber.Text == String.Empty)
            {
                labelProjectNumber.ForeColor = Color.Red;
                returnFlag = true;
            }
            else
            {
                try
                {
                    double.Parse(textBoxDetailsProjectNumber.Text);
                }
                catch
                {
                    labelProjectNumber.ForeColor = Color.Red;
                    returnFlag = true;
                }
                DataTable tempNumbersTable;
                tempNumbersTable = localInterface.Select("SELECT projectNumber FROM projects WHERE projectNumber LIKE '%" + textBoxDetailsProjectNumber.Text + "%'").Tables[0];
                if (tempNumbersTable.Rows.Count > 0)
                {
                    double temp = 0;
                    foreach (DataRow row in tempNumbersTable.Rows)
                    {
                        if (double.Parse(row[0].ToString()) > temp)
                        {
                            temp = double.Parse(row[0].ToString());
                        }
                    }
                    textBoxDetailsProjectNumber.Text = (temp + 0.1).ToString();
                    MessageBox.Show("מספר פרוייקט כבר קיים," + "\r\n" + "המספר הוחלף במספר עוקב," + "\r\n" + "באפשרותך לשנותו או לשמור שנית", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
                    labelProjectNumber.ForeColor = Color.Red;
                    returnFlag = true;
                }
            }
            if (textBoxDetailsProjectCustomerName.Text == String.Empty)
            {
                labelCustomerName.ForeColor = Color.Red;
                returnFlag = true;
            }
            try
            {
                double.Parse(textBoxDetailsProjectAmount.Text);
            }
            catch
            {
                labelAmount.ForeColor            = Color.Red;
                textBoxDetailsProjectAmount.Text = "0";
                returnFlag = true;
            }
            try
            {
                Double.Parse(textBoxDetailsProjectPriceIndex.Text);
            }
            catch
            {
                labelPriceIndex.ForeColor            = Color.Red;
                textBoxDetailsProjectPriceIndex.Text = "0";
                returnFlag = true;
            }
            if (returnFlag)
            {
                return;
            }
            short contract = 0;

            if (checkBoxDetailsProjectContract.Checked)
            {
                contract = 1;
            }
            short isClosed = 0;

            if (checkBoxDetailsProjectIsClosed.Checked)
            {
                isClosed = 1;
            }
            short projectType = 0;

            if (radioButtonProjectTypeInstilation.Checked)
            {
                projectType = 1;
            }
            localInterface.Insert("projects", "projectNumber,handler1,handler2,startDate,idCustomer,projectName,amount,curency,amountInfo,linking,priceIndex,contract,contractNotes," +
                                  "projectNotes,isClosed,archiveLocation,contractNumber,mileStones,projectType,approverName,approverPhone,approverEmail,approverFax," +
                                  "payerName,payerPhone,payerEmail,payerFax,payerAddress,approverAddress",
                                  textBoxDetailsProjectNumber.Text.Replace("'", "\\'") + "','" +
                                  comboBoxDetailsProjectHandler1.Text.Replace("'", "\\'") + "','" +
                                  comboBoxDetailsProjectHandler2.Text.Replace("'", "\\'") + "','" +
                                  MyUtills.dateToSQL(dateTimePickerDetailsProjectStart.Value) + "','" +
                                  textBoxCustomerId.Text + "','" +
                                  textBoxDetailsProjectName.Text.Replace("'", "\\'") + "','" +
                                  textBoxDetailsProjectAmount.Text + "','" +
                                  comboBoxCurency.SelectedIndex.ToString() + "','" +
                                  textBoxDetailsProjectAmountInfo.Text.Replace("'", "\\'") + "','" +
                                  comboBoxDetailsProjectlinking.SelectedIndex.ToString() + "','" +
                                  textBoxDetailsProjectPriceIndex.Text + "','" +
                                  contract.ToString() + "','" +
                                  textBoxDetailsProjectContractNotes.Text.Replace("'", "\\'") + "','" +
                                  textBoxDetailsProjectNotes.Text.Replace("'", "\\'") + "','" +
                                  isClosed.ToString() + "','" +
                                  textBoxDetailsProjectArchiveLocation.Text.Replace("'", "\\'") + "','" +
                                  textBoxDetailsProjectContractNumber.Text.Replace("'", "\\'") + "','" +
                                  textBoxDetailsProjectMileStones.Text.Replace("'", "\\'") + "','" +
                                  projectType.ToString() + "','" +
                                  textBoxApproverName.Text.Replace("'", "\\'") + "','" +
                                  textBoxApproverPhone.Text + "','" +
                                  textBoxApproverEmail.Text + "','" +
                                  textBoxApproverFax.Text + "','" +
                                  textBoxPayerName.Text.Replace("'", "\\'") + "','" +
                                  textBoxPayerPhone.Text + "','" +
                                  textBoxPayerEmail.Text + "','" +
                                  textBoxPayerFax.Text + "','" +
                                  textBoxPayerAddress.Text.Replace("'", "\\'") + "','" +
                                  textBoxApproverAddress.Text.Replace("'", "\\'"));
            if (dateTimePickerDetailsProjectPriceIndexDate.Checked)
            {
                localInterface.Update("UPDATE projects SET priceIndexDate = '" + MyUtills.dateToSQL(dateTimePickerDetailsProjectPriceIndexDate.Value) +
                                      "' WHERE projectNumber = '" + textBoxDetailsProjectNumber.Text + "' AND projectName = '" + textBoxDetailsProjectName.Text + "'");
            }
            else
            {
                localInterface.Update("UPDATE projects SET priceindexDate = NULL WHERE projectNumber = '" + textBoxDetailsProjectNumber.Text + "' AND projectName = '" + textBoxDetailsProjectName.Text + "'");
            }
            MessageBox.Show("פרוייקט חדש נשמר במערכת", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
            this.Close();
            mainForm.refreshView();
        }
示例#13
0
        private void Form_NewBill_Load(object sender, EventArgs e)
        {
            //textBoxDetailsBillAmount.Text = amount;
            textBoxDetailsBillPaid.Text = "0";
            comboBoxDetailsBillPayMethod.SelectedIndex = 0;
            textBoxCurencyRate.Text  = "0";
            textBoxBillIndex.Text    = "0";
            textBoxBillIncrease.Text = "0";
            DataTable dt = localInterface.Select("Select * FROM handlers").Tables[0];

            comboBoxDetailsBillHandlers.Items.Add("");
            foreach (DataRow dr in dt.Rows)
            {
                comboBoxDetailsBillHandlers.Items.Add(dr[0]);
            }
            comboBoxDetailsBillHandlers.SelectedItem = "מזכירה";
            DataTable dt2 = localInterface.Select("SELECT vat FROM vat WHERE date<='" + MyUtills.dateToSQL(DateTime.Now) + "' ORDER BY date DESC").Tables[0];

            textBoxBillVat.Text = "% " + dt2.Rows[0][0].ToString();
        }
示例#14
0
        private bool Save()
        {
            labelBillNumber.ForeColor     = Color.Black;
            labelProjectNumber.ForeColor  = Color.Black;
            labelProjectName.ForeColor    = Color.Black;
            buttonSelectProject.ForeColor = Color.Black;
            labelAmount.ForeColor         = Color.Black;
            labelPaid.ForeColor           = Color.Black;
            labelPayMethod.ForeColor      = Color.Black;
            labelCurencyRate.ForeColor    = Color.Black;
            labelBillIncrease.ForeColor   = Color.Black;
            labelBillIndex.ForeColor      = Color.Black;
            labelBillPart.ForeColor       = Color.Black;

            bool returnFlag = false;

            if (textBoxDetailsBillNumber.Text == String.Empty)
            {
                labelBillNumber.ForeColor     = Color.Red;
                labelProjectNumber.ForeColor  = Color.Red;
                labelProjectName.ForeColor    = Color.Red;
                buttonSelectProject.ForeColor = Color.Red;
                returnFlag = true;
            }
            try
            {
                double.Parse(textBoxDetailsBillAmount.Text);
            }
            catch
            {
                labelAmount.ForeColor = Color.Red;
                returnFlag            = true;
            }
            try
            {
                double.Parse(textBoxBillIncrease.Text);
            }
            catch
            {
                labelBillIncrease.ForeColor = Color.Red;
                returnFlag = true;
            }
            try
            {
                double.Parse(textBoxBillIndex.Text);
            }
            catch
            {
                labelBillIndex.ForeColor = Color.Red;
                returnFlag = true;
            }
            try
            {
                double.Parse(textBoxCurencyRate.Text);
                if (double.Parse(textBoxCurencyRate.Text) == 0)
                {
                    textBoxCurencyRate.Text = "1";
                }
            }
            catch
            {
                labelCurencyRate.ForeColor = Color.Red;
                returnFlag = true;
            }
            try
            {
                int.Parse(textBoxBillPart.Text);
            }
            catch
            {
                labelBillPart.ForeColor = Color.Red;
                returnFlag = true;
            }
            short isClosed = 0;

            if (returnFlag)
            {
                return(false);
            }
            if (checkBoxDetailsBillIsClosed.Checked)
            {
                isClosed = 1;
            }
            int  billPart = GetBillPart();//localInterface.Select("SELECT idBill FROM bills WHERE idProject=" + textBoxID.Text).Tables[0].Rows.Count + 1;
            bool queryOk;

            queryOk = localInterface.Insert("bills", "idBill,amount,paid,payMethod,billDate,vatDate,approvalDate,toPayDate,payDate,invoiceNumber,receiptNumber,isClosed,curencyRate,handler,billNotes,increase,billPart,currentIndex,callback",
                                            textBoxDetailsBillNumber.Text + "','" +
                                            textBoxDetailsBillAmount.Text.Replace(",", "") + "','" +
                                            textBoxDetailsBillPaid.Text.Replace(",", "") + "','" +
                                            comboBoxDetailsBillPayMethod.SelectedIndex + "','" +
                                            MyUtills.dateToSQL(dateTimePickerDetailsBillDate.Value) + "','" +
                                            MyUtills.dateToSQL(dateTimePickerDetailsBillDate.Value) + "','" +
                                            MyUtills.dateToSQL(dateTimePickerDetailsBillApproval.Value) + "','" +
                                            MyUtills.dateToSQL(dateTimePickerDetailsBillToPay.Value) + "','" +
                                            MyUtills.dateToSQL(dateTimePickerDetailsBillPay.Value) + "','" +
                                            textBoxDetailsBillInvoiceNumber.Text + "','" +
                                            textBoxDetailsBillReceiptNumber.Text + "','" +
                                            isClosed.ToString() + "','" +
                                            textBoxCurencyRate.Text + "','" +
                                            comboBoxDetailsBillHandlers.SelectedItem + "','" +
                                            textBoxBillNotes.Text.Replace("'", "\\'") + "','" +
                                            textBoxBillIncrease.Text + "','" +
                                            textBoxBillPart.Text + "','" +
                                            textBoxBillIndex.Text + "','" +
                                            MyUtills.dateToSQL(dateTimePickerDetailsBillDate.Value.AddDays(2)));


            if (!queryOk)
            {
                MessageBox.Show("שמירת חשבון חדש נכשלה", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
                return(false);
            }
            else
            {
                int       maxBillId = (int)localInterface.Select("SELECT MAX(id) FROM bills").Tables[0].Rows[0][0];
                DataTable dtProject;
                Double    projectAmount;
                double    projectToSubmit;
                double    oldProgress = 0;
                for (int i = 0; i < dataGridViewProjects.RowCount; i++)
                {
                    dtProject       = localInterface.Select("SELECT projects.amount,projects.toSubmit,COALESCE(SUM(bills_projects.percent),0) FROM projects LEFT JOIN bills_projects ON projects.idProjects=bills_projects.idProject WHERE projects.idProjects=" + dataGridViewProjects.Rows[i].Cells[0].Value.ToString() + " ORDER BY bills_projects.progress DESC LIMIT 1").Tables[0];
                    projectAmount   = Convert.ToDouble(dtProject.Rows[0][0]);
                    projectToSubmit = Convert.ToDouble(dtProject.Rows[0][1]);
                    try
                    {
                        oldProgress = Convert.ToDouble(dtProject.Rows[0][2]);
                    }
                    catch { }
                    localInterface.Insert("bills_projects", "idBill,idProject,percent,progress,paid", maxBillId.ToString() + "','" +
                                          dataGridViewProjects.Rows[i].Cells[0].Value.ToString() + "','" +
                                          (Convert.ToDouble(dataGridViewProjects.Rows[i].Cells[2].Value) / projectAmount * 100).ToString() + "','" +
                                          (oldProgress + Convert.ToDouble(dataGridViewProjects.Rows[i].Cells[2].Value) / projectAmount * 100).ToString() + "','" +
                                          (Convert.ToDouble(dataGridViewProjects.Rows[i].Cells[3].Value) / projectAmount * 100)).ToString();
                    if (projectToSubmit != oldProgress + Convert.ToDouble(dataGridViewProjects.Rows[i].Cells[2].Value) / projectAmount * 100)
                    {
                        localInterface.Update("UPDATE projects SET toSubmit=" + (oldProgress + Convert.ToDouble(dataGridViewProjects.Rows[i].Cells[2].Value) / projectAmount * 100).ToString() + " WHERE idProjects=" + dataGridViewProjects.Rows[i].Cells[0].Value.ToString());
                    }
                }

                //for (int i=0;i<projectIds.Count;i++)
                //    localInterface.Insert("bills_projects", "idBill,idProject,percent,progress", maxBillId.ToString() + "','" +
                //                                                                        projectIds[i].ToString() + "','" +
                //                                                                        projectProgress[i].ToString() + "','" +
                //                                                                        progress[i].ToString());
            }
            if (dateTimePickerDetailsBillApproval.Checked)
            {
                localInterface.Update("UPDATE bills SET approvalDate = '" + MyUtills.dateToSQL(dateTimePickerDetailsBillApproval.Value) +
                                      "' WHERE idBill = '" + textBoxDetailsBillNumber.Text + "'");
            }
            else
            {
                localInterface.Update("UPDATE bills SET approvalDate = NULL WHERE idBill = '" + textBoxDetailsBillNumber.Text + "'");
            }
            if (dateTimePickerDetailsBillToPay.Checked)
            {
                localInterface.Update("UPDATE bills SET toPayDate = '" + MyUtills.dateToSQL(dateTimePickerDetailsBillToPay.Value) +
                                      "' WHERE idBill = '" + textBoxDetailsBillNumber.Text + "'");
            }
            else
            {
                localInterface.Update("UPDATE bills SET toPayDate = NULL WHERE idBill = '" + textBoxDetailsBillNumber.Text + "'");
            }
            if (dateTimePickerDetailsBillPay.Checked)
            {
                localInterface.Update("UPDATE bills SET payDate = '" + MyUtills.dateToSQL(dateTimePickerDetailsBillPay.Value) +
                                      "' WHERE idBill = '" + textBoxDetailsBillNumber.Text + "'");
            }
            else
            {
                localInterface.Update("UPDATE bills SET payDate = NULL WHERE idBill = '" + textBoxDetailsBillNumber.Text + "'");
            }
            MessageBox.Show("חשבון חדש נשמר במערכת", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
            this.Close();
            mainForm.refreshView();
            return(true);
        }
示例#15
0
        private void dateTimePickerDetailsBillDate_ValueChanged(object sender, EventArgs e)
        {
            DateTime  dt  = dateTimePickerDetailsBillDate.Value;
            DataTable dt2 = localInterface.Select("SELECT vat FROM vat WHERE date<='" + MyUtills.dateToSQL(dt) + "' ORDER BY date DESC").Tables[0];

            textBoxBillVat.Text = "% " + dt2.Rows[0][0].ToString();
        }