Beispiel #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 = "";
                clsSellers Sel = new clsSellers();
                mdlData.colSellers.Add(Sel);
                int i = mdlData.colSellers.Count;
                mdlData.GenNumberID();
                for (int k = 0; k < mdlData.colSellers.Count; k++)
                {
                    if (mdlData.colSellers[k].ID == Convert.ToInt32(mdlData.GrnNumberID))
                    {
                        mdlData.GrnNumberID = "";
                        mdlData.GenNumberID();
                        k = 0;
                    }
                    else
                    {
                        continue;
                    }
                }
                mdlData.colSellers[i - 1].TypeContract = comboBox4.Text;
                mdlData.colSellers[i - 1].ID           = Convert.ToInt32(mdlData.GrnNumberID);
                for (int j = 0; j < mdlData.colObject.Count; j++)
                {
                    if (mdlData.colObject[j].Name == comboBox3.Text)
                    {
                        mdlData.colSellers[i - 1].ObjectN = mdlData.colObject[j].ID;
                    }
                }
                for (int j = 0; j < mdlData.colCompany.Count; j++)
                {
                    if (mdlData.colCompany[j].Name == comboBox1.Text)
                    {
                        mdlData.colSellers[i - 1].Client = mdlData.colCompany[j].ID;
                    }
                    if (mdlData.colCompany[j].Name == comboBox2.Text)
                    {
                        mdlData.colSellers[i - 1].Performer = mdlData.colCompany[j].ID;
                    }
                }
                mdlData.colSellers[i - 1].ContractNumber = textBox3.Text;
                mdlData.colSellers[i - 1].dateDoc        = textBox4.Text;

                string DirObject          = mdlData.colSellers[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 PdfFileСonsignment = System.IO.Path.GetFileName(textBox6.Text);     //Накладные
                string PdfFileAct         = System.IO.Path.GetFileName(textBox7.Text);     //Фкты
                string pathFrom;
                if (textBox7_url.Text != "")
                {
                    pathFrom = mdlData.path + @"\" + DirObject + @"\sellers\" + PdfFileDog;
                    mdlData.colSellers[i - 1].pdf_dog = pathFrom;
                    File.Copy(textBox7_url.Text, pathFrom, true);
                }
                if (textBox6_url.Text != "")
                {
                    pathFrom = mdlData.path + @"\" + DirObject + @"\sellers\" + PdfFileInvoice;
                    mdlData.colSellers[i - 1].pdf_invoice = pathFrom;
                    File.Copy(textBox6_url.Text, pathFrom, true);
                }
                if (textBox5_url.Text != "")
                {
                    pathFrom = mdlData.path + @"\" + DirObject + @"\sellers\" + PdfFileKc;
                    mdlData.colSellers[i - 1].pdf_kc = pathFrom;
                    File.Copy(textBox5_url.Text, pathFrom, true);
                }
                if (textBox6.Text != "")
                {
                    pathFrom = mdlData.path + @"\" + DirObject + @"\sellers\" + PdfFileСonsignment;
                    mdlData.colSellers[i - 1].pdf_consignment = pathFrom;
                    File.Copy(textBox6.Text, pathFrom, true);
                }
                if (textBox7.Text != "")
                {
                    pathFrom = mdlData.path + @"\" + DirObject + @"\sellers\" + PdfFileAct;
                    mdlData.colSellers[i - 1].pdf_act = pathFrom;
                    File.Copy(textBox7.Text, pathFrom, true);
                }
                mdlData.colSellers[i - 1].note = textBox5.Text;
                //Запись в БД
                mdlData.ready = true;
                mdlData.ConnectDataBase();
                SqlCommand cmd = mdlData.cnn.CreateCommand();
                cmd.CommandText = "INSERT INTO sellers(ID,ObjectN,Client,Performer,TypeContract,ContractNumber,dateDoc,pdf_kc,pdf_invoice,pdf_dog,pdf_consignment,pdf_act,note) VALUES ('" + mdlData.colSellers[i - 1].ID +
                                  "','" + mdlData.colSellers[i - 1].ObjectN +
                                  "','" + mdlData.colSellers[i - 1].Client +
                                  "','" + mdlData.colSellers[i - 1].Performer +
                                  "','" + mdlData.colSellers[i - 1].TypeContract +
                                  "','" + mdlData.colSellers[i - 1].ContractNumber +
                                  "','" + mdlData.colSellers[i - 1].dateDoc +
                                  "','" + mdlData.colSellers[i - 1].pdf_kc +
                                  "','" + mdlData.colSellers[i - 1].pdf_invoice +
                                  "','" + mdlData.colSellers[i - 1].pdf_dog +
                                  "','" + mdlData.colSellers[i - 1].pdf_consignment +
                                  "','" + mdlData.colSellers[i - 1].pdf_act +
                                  "','" + mdlData.colSellers[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);
            }
        }