private bool grdInputsDocumentsGoods_Restore()
        {
            grdInputsDocumentsGoods.GetGridState();
            grdInputsDocumentsGoods.DataSource = null;
            if (grdInputsDocuments.Rows.Count == 0 ||
                oInputDocumentCur.ID == null ||
                (grdInputsDocuments.CurrentRow != null && grdInputsDocuments.IsStatusRow(grdInputsDocuments.CurrentRow.Index)))
            {
                return(true);
            }

            oInputDocumentList.FillTableInputsDocumentsGoods((int)oInputDocumentCur.ID);
            grdInputsDocumentsGoods.Restore(oInputDocumentList.TableInputsDocumentsGoods);
            return(oInputDocumentList.ErrorNumber == 0);
        }
        private void btnAddGood_Click(object sender, EventArgs e)
        {
            _SelectedPackingsIDList = null;
            _SelectedPackingsIDList = _SelectedIDList = null;
            int       nGoodID = 0;
            bool      nFound  = false;
            DataTable dtSource;
            Good      oGoodTemp = new Good();

            if (_SelectedInputDocumentID != null || _SelectedInputID != null)
            {
                if (_SelectedInputDocumentID != null)
                {
                    InputDocument oInputDocument = new InputDocument();
                    oInputDocument.ID = _SelectedInputDocumentID;
                    oInputDocument.FillTableInputsDocumentsGoods();
                    if (oInputDocument.TableInputsDocumentsGoods.Rows.Count == 0)
                    {
                        RFMMessage.MessageBoxAttention("В выбранном приходном документе нет товаров...");
                        return;
                    }
                    dtSource = oInputDocument.TableInputsDocumentsGoods.Copy();
                }
                else
                {
                    Input oInput = new Input();
                    oInput.ID = _SelectedInputID;
                    oInput.FillTableInputsGoods();
                    if (oInput.TableInputsGoods.Rows.Count == 0)
                    {
                        RFMMessage.MessageBoxAttention("В выбранном задании на приход нет товаров...");
                        return;
                    }
                    dtSource = oInput.TableInputsGoods.Copy();
                }
                if (StartForm(new frmSelectID(this, dtSource,
                                              "GoodAlias, GoodBarcode, Articul, GoodGroupName, GoodBrandName, Retention, Weighting, GoodActual, CountryName, ERPCode",
                                              "Товар, Штрих-Код, Артикул, Группа, Бренд, Срок годн., Вес., Акт., Страна, ERP-код", true)) != DialogResult.Yes)
                {
                    _SelectedIDList = null;
                    return;
                }
                if (_SelectedIDList == null || !_SelectedIDList.Contains(","))
                {
                    return;
                }
                string[]      cIDList = _SelectedIDList.Split(',');
                StringBuilder sb      = new StringBuilder();
                DataRow       dr;
                for (int i = 0; i < cIDList.Length; i++)
                {
                    for (int j = 0; j < dtSource.Rows.Count; j++)
                    {
                        dr = dtSource.Rows[j];
                        if (cIDList[i] == dr["ID"].ToString())
                        {
                            sb.Append(dr["PackingID"].ToString() + ",");
                        }
                    }
                }
                oGoodTemp.PackingsIDList = "," + sb;
                oGoodTemp.FillData();
            }

            else
            {
                if (StartForm(new frmSelectOnePacking(this, true)) == DialogResult.Yes)
                {
                    if (_SelectedPackingsIDList == null || !_SelectedPackingsIDList.Contains(","))
                    {
                        return;
                    }

                    RFMCursorWait.Set(true);
                    oGoodTemp.PackingsIDList = "," + _SelectedPackingsIDList;
                    oGoodTemp.FillData();
                    if (oGoodTemp.ErrorNumber != 0 || oGoodTemp.MainTable == null || oGoodTemp.MainTable.Rows.Count == 0)
                    {
                        RFMCursorWait.Set(false);
                        return;
                    }
                }
            }
            foreach (DataRow rg in oGoodTemp.MainTable.Rows)
            {
                // нет ли уже такого товара?
                nGoodID = Convert.ToInt32(rg["GoodID"]);
                nFound  = false;

                foreach (DataRow drTemp in tGoodsVeterinaries.Rows)
                {
                    if (Convert.ToInt32(drTemp["GoodID"]) == nGoodID)
                    {
                        nFound = true;
                        if (oGoodTemp.MainTable.Rows.Count == 1)
                        {
                            RFMCursorWait.Set(false);
                            RFMMessage.MessageBoxError("Такой товар уже в списке...");
                            RFMCursorWait.Set(true);
                        }
                        break;
                    }
                }
                if (!nFound)
                {
                    // добавляем новую строку для выбранного товара
                    DataTable dtTemp = tGoodsVeterinaries.Clone();
                    dtTemp.Columns["GoodID"].AllowDBNull = true;
                    DataRow dr = dtTemp.Rows.Add();
                    dr["GoodID"]        = nGoodID;
                    dr["GoodName"]      = rg["GoodName"];
                    dr["GoodAlias"]     = rg["GoodAlias"];
                    dr["GoodBarCode"]   = rg["GoodBarCode"];
                    dr["Articul"]       = rg["Articul"];
                    dr["GoodGroupName"] = rg["GoodGroupName"];
                    dr["GoodBrandName"] = rg["GoodBrandName"];
                    dr["CountryName"]   = rg["CountryName"];
                    dr["Weighting"]     = rg["Weighting"];
                    dr["GoodActual"]    = rg["GoodActual"];
                    dr["Netto"]         = rg["Netto"];
                    dr["Brutto"]        = rg["Brutto"];
                    dr["Retention"]     = rg["Retention"];
                    dr["GoodERPCode"]   = rg["GoodERPCode"];

                    tGoodsVeterinaries.ImportRow(dr);
                }
                // встать на последнюю добавленную строку
                if (nGoodID != 0)
                {
                    grdData.GridSource.Position = grdData.GridSource.Find("GoodID", nGoodID);
                    if (grdData.GridSource.Position < 0)
                    {
                        grdData.GridSource.MoveFirst();
                    }
                }
                RFMCursorWait.Set(false);
            }
            _SelectedPackingsIDList = null;

            btnDeleteGood.Enabled = (grdData.Rows.Count > 0);
        }
Ejemplo n.º 3
0
        private bool dgvInputDocumentGoods_Restore()
        {
            oInputDocument.ClearError();
            oInputDocument.FillData();
            if (oInputDocument.ErrorNumber == 0)
            {
                if (nInputDocumentID != 0)
                {
                    oInputDocument.FillTableInputsDocumentsGoods();
                }
                else
                {
                    oInputDocument.FillTableInputsDocumentsGoodsFromInput((int)nInputID);
                }
                if (oInputDocument.ErrorNumber == 0)
                {
                    oInputDocument.TableInputsDocumentsGoods.PrimaryKey                                 = null;
                    oInputDocument.TableInputsDocumentsGoods.Columns["ID"].Unique                       = false;
                    oInputDocument.TableInputsDocumentsGoods.Columns["ID"].AllowDBNull                  = true;
                    oInputDocument.TableInputsDocumentsGoods.Columns["InputDocumentGoodID"].Unique      = false;
                    oInputDocument.TableInputsDocumentsGoods.Columns["InputDocumentGoodID"].AllowDBNull = true;
                    //oInputDocument.TableInputsDocumentsGoods.Columns["InputDocumentGoodID"].DefaultValue = -1;
                    //oInputDocument.TableInputsDocumentsGoods.PrimaryKey = new DataColumn[] { oInputDocument.TableInputsDocumentsGoods.Columns["InputDocumentGoodID"] };

                    // колонки для исправления
                    if (oInputDocument.TableInputsDocumentsGoods.Columns["QntWished"] == null)
                    {
                        oInputDocument.TableInputsDocumentsGoods.Columns.Add("QntWished", System.Type.GetType("System.Decimal"));
                    }
                    if (oInputDocument.TableInputsDocumentsGoods.Columns["QntBrought"] == null)
                    {
                        oInputDocument.TableInputsDocumentsGoods.Columns.Add("QntBrought", System.Type.GetType("System.Decimal"));
                    }
                    if (oInputDocument.TableInputsDocumentsGoods.Columns["BoxWished"] == null)
                    {
                        oInputDocument.TableInputsDocumentsGoods.Columns.Add("BoxWished", System.Type.GetType("System.Decimal"));
                    }
                    if (oInputDocument.TableInputsDocumentsGoods.Columns["BoxBrought"] == null)
                    {
                        oInputDocument.TableInputsDocumentsGoods.Columns.Add("BoxBrought", System.Type.GetType("System.Decimal"));
                    }
                    // колонка для суммы
                    if (oInputDocument.TableInputsDocumentsGoods.Columns["PriceSum"] == null)
                    {
                        oInputDocument.TableInputsDocumentsGoods.Columns.Add("PriceSum", System.Type.GetType("System.Decimal"));
                    }

                    // заполнить начальные значения
                    decimal nAmount = 0;
                    decimal nQnt    = 0;
                    decimal nBox    = 0;
                    foreach (DataRow droRow in oInputDocument.TableInputsDocumentsGoods.Rows)
                    {
                        droRow["BoxBrought"]    =
                            droRow["BoxWished"] =
                                droRow["Box"];
                        droRow["QntBrought"]    =
                            droRow["QntWished"] =
                                droRow["Qnt"];
                        droRow["PriceSum"] = (decimal)droRow["QntBrought"] * (decimal)droRow["Price"];
                        nQnt    += (decimal)droRow["QntBrought"];
                        nBox    += (decimal)droRow["BoxBrought"];
                        nAmount += (decimal)droRow["PriceSum"];

                        // НДС
                        if (Convert.IsDBNull(droRow["Vat"]) || droRow["Vat"] == null)
                        {
                            droRow["Vat"] = 0;
                        }

                        /*
                         * if (Convert.IsDBNull(droRow["Vat"]) || droRow["Vat"] == null || (decimal)droRow["Vat"] == 0)
                         * {
                         *      droRow["Vat"] = oGood.Vat((int)droRow["PackingID"], oInputDocument.DateInput);
                         * }
                         */
                    }
                    dgvInputDocumentGoods.Restore(oInputDocument.TableInputsDocumentsGoods);
                    lblTotalAmount.Text = nAmount.ToString("### ### ##0.00").Trim();
                    lblTotalQnt.Text    = nQnt.ToString("### ### ##0").Trim();
                    lblTotalBox.Text    = nBox.ToString("# ### ##0.0").Trim();
                }
            }
            return(oInputDocument.ErrorNumber == 0);
        }