示例#1
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            Int32 docNumber = 0;
            Int32 scladNumber;
            Int32 customerNumber;

            Int32  prevScladNumber    = 0;
            Int32  prevCustomerNumber = 0;
            int    linePerDoc         = 0;
            string prevMaterialName   = "";

            List <dataDataSet.AddTrebovaniyaViewRow> rows = new List <dataDataSet.AddTrebovaniyaViewRow>();

            if (dgvTrebovaniya.Rows.Count == 0)
            {
                MessageBox.Show("Нет материалов для формирования требований", "Внимание");
                return;
            }

            Cursor = Cursors.WaitCursor;
            dataDataSet1 newds = new dataDataSet1();

            dataDataSet1.TrebovanieRow r = (dataDataSet1.TrebovanieRow)newds.Trebovanie.NewRow();

            /*
             *          // если выделено больше 1 строки, печатаем выделенные
             *          if (dgvTrebovaniya.SelectedRows.Count > 1)
             *          {
             *              for (int i = 0; i < dgvTrebovaniya.SelectedRows.Count; i++)
             *              {
             *                  dataDataSet.AddTrebovaniyaViewRow row = (dataDataSet.AddTrebovaniyaViewRow)((DataRowView)dgvTrebovaniya.SelectedRows[i].DataBoundItem).Row;
             *                  rows.Add(row);
             *              }
             *          }
             *          else // иначе все строки
             *          {
             *              for (int i = 0; i < dgvTrebovaniya.Rows.Count; i++)
             *              {
             *                  dataDataSet.AddTrebovaniyaViewRow row = (dataDataSet.AddTrebovaniyaViewRow)((DataRowView)dgvTrebovaniya.Rows[i].DataBoundItem).Row;
             *                  rows.Add(row);
             *              }
             *          }
             *
             *          for (int i = 0; i < rows.Count; i++)
             *          {
             *
             *              dataDataSet.AddTrebovaniyaViewRow row = rows[i];
             */
            for (int i = 0; i < dgvTrebovaniya.SelectedRows.Count; i++)
            {
                dataDataSet1.AddTrebovaniyaViewRow row = (dataDataSet1.AddTrebovaniyaViewRow)((DataRowView)dgvTrebovaniya.SelectedRows[i].DataBoundItem).Row;
                dataDataSet1.TrebovanieDetailsRow  d   = (dataDataSet1.TrebovanieDetailsRow)newds.TrebovanieDetails.NewRow();
                if (row.IsMaterialNameNull())
                {
                    MessageBox.Show("Не заполнено название материала", "Внимание");
                    continue;
                }

                if (Int32.TryParse(row.Sclad, out scladNumber))
                {
                }
                ;
                customerNumber = row.Customer;

                if (prevCustomerNumber != customerNumber || prevScladNumber != scladNumber || linePerDoc > 7)
                {
                    linePerDoc = 0;
                    r          = (dataDataSet1.TrebovanieRow)newds.Trebovanie.NewRow();

                    if (Int32.TryParse(tbTrebovanieNumber.Text, out docNumber))
                    {
                        r.DocNumber             = docNumber;
                        tbTrebovanieNumber.Text = (++docNumber).ToString();
                    }
                    r.Sclad   = scladNumber;
                    r.DocDate = dtpTrebovanieDate.Value;
                    r.Status  = 0;
                    r.NЦеха   = row.Customer;
                    if (oneOrder == true)
                    {
                        r.OrderId     = row.OrderId;
                        r.OrderNumber = row.OrderNumber;
                    }

                    newds.Trebovanie.AddTrebovanieRow(r);

                    taTrebovanie.Update(newds);
                    newds.Trebovanie.AcceptChanges();

                    prevScladNumber    = scladNumber;
                    prevCustomerNumber = customerNumber;
                }

                d.SetParentRow(r);
                d.OrderId   = row.OrderId;
                d.MatCartId = row.MatCartId;

                if (row.IsMaterialCodeNull() == false)
                {
                    d.MaterialCode = row.MaterialCode;
                }

                d.Material = row.MaterialName;

                d.Ed   = row.Ed;
                d.Kol1 = row.Qty;
                d.Kol2 = 0.0;



                if (row.IsASUPCODENull() == false)
                {
                    d.ASUPCODE = row.ASUPCODE;
                }

                if (d.Material != prevMaterialName)
                {
                    linePerDoc++;
                }

                prevMaterialName = d.Material;
                newds.TrebovanieDetails.AddTrebovanieDetailsRow(d);
            }
            tam.UpdateAll(newds);
            Cursor = Cursors.Default;
            Properties.Settings.Default.TrebovanieLastNumber = docNumber;
            Properties.Settings.Default.Save();
            Close();
        }
示例#2
0
 public virtual int Update(dataDataSet1 dataSet) {
     return this.Adapter.Update(dataSet, "Products");
 }
示例#3
0
 public virtual int Update(dataDataSet1.ProductsDataTable dataTable) {
     return this.Adapter.Update(dataTable);
 }
示例#4
0
 public virtual int Fill(dataDataSet1.ProductsDataTable dataTable) {
     this.Adapter.SelectCommand = this.CommandCollection[0];
     if ((this.ClearBeforeFill == true)) {
         dataTable.Clear();
     }
     int returnValue = this.Adapter.Fill(dataTable);
     return returnValue;
 }
示例#5
0
 public virtual int Update(dataDataSet1 dataSet) {
     return this.Adapter.Update(dataSet, "Images");
 }
示例#6
0
        private void TrebovanieForm_Load(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            taDepartmentsView.Fill(ds.DepartmentsView);

            if (id > 0 && copy == false)
            {
                taTrebovanie.FillById(ds.Trebovanie, id);
                taTrebovanieDetails.FillById(ds.TrebovanieDetails, id);
                dataDataSet1.TrebovanieRow r = (dataDataSet1.TrebovanieRow)ds.Trebovanie.Rows[0];
                cbCustomer.SelectedValue = r.NЦеха;
            }
            else
            {
                taTrebovanie.Adapter.RowUpdated += Adapter_RowUpdated;
                isNewDoc = true;

                if (copy == true)
                {
                    Texac.dataDataSet1 tmpDs = new dataDataSet1();
                    taTrebovanie.FillById(tmpDs.Trebovanie, id);
                    taTrebovanieDetails.FillById(tmpDs.TrebovanieDetails, id);

                    if (tmpDs.Trebovanie.Rows.Count > 0)
                    {
                        dataDataSet1.TrebovanieRow r      = (dataDataSet1.TrebovanieRow)tmpDs.Trebovanie.Rows[0];
                        dataDataSet1.TrebovanieRow newRow = (dataDataSet1.TrebovanieRow)ds.Trebovanie.NewRow();

                        if (r.IsScladNull())
                        {
                            newRow.SetScladNull();
                        }
                        else
                        {
                            newRow.Sclad = r.Sclad;
                        }

                        if (r.IsNЦехаNull())
                        {
                            newRow.SetNЦехаNull();
                        }
                        else
                        {
                            newRow.NЦеха = r.NЦеха;
                        }

                        ds.Trebovanie.AddTrebovanieRow(newRow);

                        for (int i = 0; i < tmpDs.TrebovanieDetails.Rows.Count; i++)
                        {
                            dataDataSet1.TrebovanieDetailsRow newDetRow = (dataDataSet1.TrebovanieDetailsRow)ds.TrebovanieDetails.NewRow();
                            dataDataSet1.TrebovanieDetailsRow rd        = (dataDataSet1.TrebovanieDetailsRow)tmpDs.TrebovanieDetails.Rows[i];
                            newDetRow.tblTrebovanielId = newRow.TrebovanieId;
                            try
                            {
                                if (rd.IsASUPCODENull() == false)
                                {
                                    newDetRow.ASUPCODE = rd.ASUPCODE;
                                }

                                if (rd.IsEdNull() == false)
                                {
                                    newDetRow.Ed = rd.Ed;
                                }

                                if (rd.IsKol1Null() == false)
                                {
                                    newDetRow.Kol1 = rd.Kol1;
                                }

                                if (rd.IsKol2Null() == false)
                                {
                                    newDetRow.Kol2 = rd.Kol2;
                                }

                                if (rd.IsMatCartIdNull() == false)
                                {
                                    newDetRow.MatCartId = rd.MatCartId;
                                }

                                if (rd.IsMaterialNull() == false)
                                {
                                    newDetRow.Material = rd.Material;
                                }

                                if (rd.IsMaterialCodeNull() == false)
                                {
                                    newDetRow.MaterialCode = rd.MaterialCode;
                                }

                                if (rd.IsOrderIdNull() == false)
                                {
                                    newDetRow.OrderId = rd.OrderId;
                                }

                                ds.TrebovanieDetails.AddTrebovanieDetailsRow(newDetRow);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.ToString());
                            }
                        }
                    }
                }
                else
                {
                    bsTrebovanie.AddNew();
                    cbCustomer.SelectedIndex = -1;
                }

                dtpDocDate.Value = DateTime.Now;
                int docNumber = Properties.Settings.Default.TrebovanieLastNumber;
                tbTrebovanieNumber.Text = (++docNumber).ToString();
            }
            Cursor.Current = Cursors.Default;
        }