Example #1
0
        // Процедура заполнения пустыми множествами коллекций по
        // количеству сторк соответствующих таблиц баз данных
        private void CreateCollection()
        {
            mdlData.colCompany.Clear();
            IList <clsCompany> cCompany = new List <clsCompany>();

            for (int i = 1; i <= TabCompany.Rows.Count; i++)
            {
                clsCompany D = new clsCompany();
                cCompany.Add(D);
            }
            mdlData.colCompany = cCompany;
            mdlData.colSellers.Clear();
            IList <clsSellers> cSellers = new List <clsSellers>();

            for (int i = 1; i <= TabSellers.Rows.Count; i++)
            {
                clsSellers D = new clsSellers();
                cSellers.Add(D);
            }
            mdlData.colSellers = cSellers;
            mdlData.colCustomer.Clear();
            IList <clsCustomer> cCustomer = new List <clsCustomer>();

            for (int i = 1; i <= TabCustomer.Rows.Count; i++)
            {
                clsCustomer D = new clsCustomer();
                cCustomer.Add(D);
            }
            mdlData.colCustomer = cCustomer;
            mdlData.colObject.Clear();
            IList <clsObject> cObject = new List <clsObject>();

            for (int i = 1; i <= TabObject.Rows.Count; i++)
            {
                clsObject D = new clsObject();
                cObject.Add(D);
            }
            mdlData.colObject = cObject;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox3.Text == "" || textBox4.Text == "" || comboBox1.Text == "" || comboBox2.Text == "" || comboBox3.Text == "" /*||textBox7_url.Text==""*/)
            {
                MessageBox.Show("Пожалуйста заполните все поля отмеченные звездочкой.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //Добавление в коллекцию
            try
            {
                mdlData.GrnNumberID = "";
                clsCustomer Cust = new clsCustomer();
                mdlData.colCustomer.Add(Cust);
                int i = mdlData.colCustomer.Count;
                mdlData.GenNumberID();
                for (int k = 0; k < mdlData.colCustomer.Count; k++)
                {
                    if (mdlData.colCustomer[k].ID == Convert.ToInt32(mdlData.GrnNumberID))
                    {
                        mdlData.GrnNumberID = "";
                        mdlData.GenNumberID();
                        k = 0;
                    }
                    else
                    {
                        continue;
                    }
                }

                mdlData.colCustomer[i - 1].ID = Convert.ToInt32(mdlData.GrnNumberID);
                for (int j = 0; j < mdlData.colObject.Count; j++)
                {
                    if (mdlData.colObject[j].Name == comboBox3.Text)
                    {
                        mdlData.colCustomer[i - 1].ObjectN = mdlData.colObject[j].ID;
                    }
                }
                for (int j = 0; j < mdlData.colCompany.Count; j++)
                {
                    if (mdlData.colCompany[j].Name == comboBox1.Text)
                    {
                        mdlData.colCustomer[i - 1].Client = mdlData.colCompany[j].ID;
                    }
                    if (mdlData.colCompany[j].Name == comboBox2.Text)
                    {
                        mdlData.colCustomer[i - 1].Performer = mdlData.colCompany[j].ID;
                    }
                }
                mdlData.colCustomer[i - 1].ContractNumber = textBox3.Text;
                mdlData.colCustomer[i - 1].dateDoc        = textBox4.Text;
                string DirObject      = mdlData.colCustomer[i - 1].ObjectN.ToString();
                string PdfFileKc      = System.IO.Path.GetFileName(textBox5_url.Text); //КС
                string PdfFileInvoice = System.IO.Path.GetFileName(textBox6_url.Text); //счет-фактура
                string PdfFileDog     = System.IO.Path.GetFileName(textBox7_url.Text); //договор
                string pathFrom;
                if (textBox7_url.Text != "")
                {
                    pathFrom = mdlData.path + @"\" + DirObject + @"\customer\" + PdfFileDog;
                    mdlData.colCustomer[i - 1].pdf_dog = pathFrom;
                    File.Copy(textBox7_url.Text, pathFrom, true);
                }
                if (textBox6_url.Text != "")
                {
                    pathFrom = mdlData.path + @"\" + DirObject + @"\customer\" + PdfFileInvoice;
                    mdlData.colCustomer[i - 1].pdf_invoice = pathFrom;
                    File.Copy(textBox6_url.Text, pathFrom, true);
                }
                if (textBox5_url.Text != "")
                {
                    pathFrom = mdlData.path + @"\" + DirObject + @"\customer\" + PdfFileKc;
                    mdlData.colCustomer[i - 1].pdf_kc = pathFrom;
                    File.Copy(textBox5_url.Text, pathFrom, true);
                }
                mdlData.colCustomer[i - 1].note = textBox5.Text;
                //Запись в БД
                mdlData.ready = true;
                mdlData.ConnectDataBase();
                SqlCommand cmd = mdlData.cnn.CreateCommand();
                cmd.CommandText = "INSERT INTO customer(ID,ObjectN,Client,Performer,ContractNumber,dateDoc,pdf_kc,pdf_invoice,pdf_dog,note) VALUES ('" + mdlData.colCustomer[i - 1].ID +
                                  "','" + mdlData.colCustomer[i - 1].ObjectN +
                                  "','" + mdlData.colCustomer[i - 1].Client +
                                  "','" + mdlData.colCustomer[i - 1].Performer +
                                  "','" + mdlData.colCustomer[i - 1].ContractNumber +
                                  "','" + mdlData.colCustomer[i - 1].dateDoc +
                                  "','" + mdlData.colCustomer[i - 1].pdf_kc +
                                  "','" + mdlData.colCustomer[i - 1].pdf_invoice +
                                  "','" + mdlData.colCustomer[i - 1].pdf_dog +
                                  "','" + mdlData.colCustomer[i - 1].note + "')";
                cmd.ExecuteNonQuery();
                MessageBox.Show("Запись добавлена", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
                mdlData.StatusAdd = true;
                mdlData.cnn.Close();
                addI.Value                = i;
                addI.Value_ObjectN        = comboBox3.Text;
                addI.Value_Client         = comboBox1.Text;
                addI.Value_Performer      = comboBox2.Text;
                mdlData.CountScanDocument = 0;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Не удалось добавить объект: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //this.Close();
            }
        }