private bool grdInputsDocuments_Restore()
        {
            RFMCursorWait.Set(true);
            RFMCursorWait.LockWindowUpdate(FindForm().Handle);

            oInputDocumentCur.ClearOne();

            oInputDocumentList.ClearError();
            oInputDocumentList.ClearFilters();
            oInputDocumentList.ID     = null;
            oInputDocumentList.IDList = null;

            // собираем условия

            // даты
            if (!dtrDates.dtpBegDate.IsEmpty)
            {
                oInputDocumentList.FilterDateBeg = dtrDates.dtpBegDate.Value.Date;
            }
            if (!dtrDates.dtpEndDate.IsEmpty)
            {
                oInputDocumentList.FilterDateEnd = dtrDates.dtpEndDate.Value.Date;
            }

            // доставка?
            if (optDeliveryNeed.Checked)
            {
                oInputDocumentList.FilterDeliveryNeed = true;
            }
            if (optDeliveryNeedNot.Checked)
            {
                oInputDocumentList.FilterDeliveryNeed = false;
            }

            // клиенты-поставщики
            if (txtPartnerSourceNameContext.Text.Trim().Length > 0)
            {
                Partner oPartnerSource = new Partner();
                oPartnerSource.FilterNameContext = txtPartnerSourceNameContext.Text.Trim();
                oPartnerSource.FillData();
                oInputDocumentList.FilterPartnersSourceList = "";
                foreach (DataRow rcs in oPartnerSource.MainTable.Rows)
                {
                    oInputDocumentList.FilterPartnersSourceList += rcs["ID"].ToString() + ",";
                }
            }
            if (ucSelectRecordID_PartnersSource.IsSelectedExist)
            {
                oInputDocumentList.FilterPartnersSourceList += ucSelectRecordID_PartnersSource.GetIdString();
            }

            // клиенты-получатели
            if (txtPartnerTargetNameContext.Text.Trim().Length > 0)
            {
                Partner oPartnerTarget = new Partner();
                oPartnerTarget.FilterNameContext = txtPartnerTargetNameContext.Text.Trim();
                oPartnerTarget.FillData();
                oInputDocumentList.FilterPartnersTargetList = "";
                foreach (DataRow rct in oPartnerTarget.MainTable.Rows)
                {
                    oInputDocumentList.FilterPartnersTargetList += rct["ID"].ToString() + ",";
                }
            }
            if (ucSelectRecordID_PartnersTarget.IsSelectedExist)
            {
                oInputDocumentList.FilterPartnersTargetList += ucSelectRecordID_PartnersTarget.GetIdString();
            }

            // владельцы
            if (ucSelectRecordID_Owners.IsSelectedExist)
            {
                oInputDocumentList.FilterOwnersList = ucSelectRecordID_Owners.GetIdString();
            }

            // рейс?
            if (optTripExists.Checked)
            {
                oInputDocumentList.FilterTripExists = true;
            }
            if (optTripExistsNot.Checked)
            {
                oInputDocumentList.FilterTripExists = false;
            }

            // выбранные товары
            if (sSelectedPackingsIDList.Length > 0)
            {
                oInputDocumentList.FilterPackingsList = sSelectedPackingsIDList;
            }

            // подтверждение
            if (optInputsDocumentsIsConfirmedNot.Checked)
            {
                oInputDocumentList.FilterIsConfirmed = false;
            }
            if (optInputsDocumentsIsConfirmed.Checked)
            {
                oInputDocumentList.FilterIsConfirmed = true;
            }

            // по рейсу
            string sTripsList = "";

            if (txtTripAliasContext.Text.Trim().Length > 0)
            {
                Trip oTripFilter = new Trip();
                oTripFilter.FilterAliasContext = txtTripAliasContext.Text.Trim();
                oTripFilter.FillData();
                if (oTripFilter.ErrorNumber == 0 && oTripFilter.MainTable != null)
                {
                    foreach (DataRow tr in oTripFilter.MainTable.Rows)
                    {
                        sTripsList += tr["ID"].ToString() + ",";
                    }
                }
                oInputDocumentList.FilterTripsList = sTripsList;
            }
            if (numTripID.Value > 0)
            {
                if (oInputDocumentList.FilterTripsList == null)
                {
                    oInputDocumentList.FilterTripsList = Convert.ToInt32(numTripID.Value).ToString();
                }
                else
                {
                    oInputDocumentList.FilterTripsList += Convert.ToInt32(numTripID.Value).ToString();
                }
            }

            // хосты
            if (nUserHostID.HasValue)
            {
                oInputDocumentList.FilterHostsList = nUserHostID.ToString();
            }
            else
            {
                if (ucSelectRecordID_Hosts.IsSelectedExist)
                {
                    oInputDocumentList.FilterHostsList = ucSelectRecordID_Hosts.GetIdString();
                }
            }

            // начальные условия
            if (oInputDocument != null)
            {
                if (oInputDocument.FilterOwnersList != null)
                {
                    oInputDocumentList.FilterOwnersList = oInputDocument.FilterOwnersList;
                }
                if (oInputDocument.FilterPartnersSourceList != null)
                {
                    oInputDocumentList.FilterPartnersSourceList = oInputDocument.FilterPartnersSourceList;
                }
                if (oInputDocument.FilterPartnersTargetList != null)
                {
                    oInputDocumentList.FilterPartnersTargetList = oInputDocument.FilterPartnersTargetList;
                }
                if (oInputDocument.FilterHostsList != null)
                {
                    if (!nUserHostID.HasValue)
                    {
                        oInputDocumentList.FilterHostsList = oInputDocument.FilterHostsList;
                    }
                    else
                    {
                        if (!((string)("," + oInputDocument.FilterHostsList + ",")).Contains("," + nUserHostID.ToString().Trim() + ","))
                        {
                            oInputDocumentList.FilterHostsList = "-1";
                        }
                    }
                }
            }
            //

            grdInputsDocumentsGoods.DataSource = null;

            grdInputsDocuments.GetGridState();

            oInputDocumentList.FillData();
            grdInputsDocuments.IsLockRowChanged = true;
            grdInputsDocuments.Restore(oInputDocumentList.MainTable);
            tmrRestore.Enabled = true;

            RFMCursorWait.LockWindowUpdate(IntPtr.Zero);
            RFMCursorWait.Set(false);

            return(oInputDocumentList.ErrorNumber == 0);
        }
예제 #2
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);
        }