Esempio n. 1
0
 private bool grdOutputsDocuments_Restore()
 {
     WaitOn(this);
     grdOutputsDocuments.DataSource     = null;
     oOutputDocument.FilterDateBeg      = dtrDates.dtpBegDate.Value;
     oOutputDocument.FilterDateEnd      = dtrDates.dtpEndDate.Value;
     oOutputDocument.FilterDeliveryNeed = true;
     oOutputDocument.FillData();
     if (oOutputDocument.ErrorNumber == 0 && oOutputDocument.MainTable != null)
     {
         if (oOutputDocument.MainTable.Rows.Count == 0)
         {
             RFMMessage.MessageBoxInfo("Нет данных...");
         }
         else
         {
             string sFilter = "DeliveryPrice > 0";
             if (chkFactureNeedOnly.Checked)
             {
                 sFilter += " and PF_FactureNeed = true";
             }
             dt = CopyTable(oOutputDocument.MainTable, "dt", sFilter, "DateOutput, FactureNumber, TripAlias, PartnerTargetName, ID");
             if (dt != null)
             {
                 grdOutputsDocuments.Restore(dt);
             }
         }
     }
     ShowTotal();
     WaitOff(this);
     return(oOutputDocument.ErrorNumber == 0);
 }
Esempio n. 2
0
        private void frmOutputsDocumentsVeterinaryBlankData_Load(object sender, EventArgs e)
        {
            oOutputDocument.IDList = sOutputsDocumentsList;
            oOutputDocument.FillData();

            // товары каждого заказа
            bool bVeterinaryUpdate = false;

            foreach (DataRow or in oOutputDocument.MainTable.Rows)
            {
                nOutputDocumentID = (int)or["ID"];
                bVeterinaryUpdate = false;

                // если еще не заполнены сведения по вет.св-вам - заполнить
                oOutputDocument.FillTableOutputsDocumentsGoods(nOutputDocumentID);
                if (oOutputDocument.ErrorNumber != 0 || oOutputDocument.TableOutputsDocumentsGoods == null)
                {
                    continue;
                }
                foreach (DataRow odg in oOutputDocument.TableOutputsDocumentsGoods.Rows)
                {
                    if (Convert.IsDBNull(odg["GoodVeterinaryID"]))
                    {
                        bVeterinaryUpdate = true;
                        break;
                    }
                }
                if (bVeterinaryUpdate)
                {
                    oOutputDocument.SetGoodVeterinaryID(nOutputDocumentID, true);
                }
            }

            btnGo_Click(null, null);

            // ФИО ветеринара
            string sVeterinarFio = "";

            if (dt != null && dt.Rows.Count > 0)
            {
                sVeterinarFio = dt.Rows[0]["VeterinarFIO"].ToString();
                if (sVeterinarFio == null || sVeterinarFio.Length == 0)
                {
                    User oUser = new User();
                    oUser.ReFillOne(((RFMFormMain)Application.OpenForms[0]).UserID);
                    Employee oEmployeeVeterinar = new Employee();
                    if (oUser.EmployeeID.HasValue)
                    {
                        oEmployeeVeterinar.ReFillOne((int)oUser.EmployeeID);
                        sVeterinarFio = oEmployeeVeterinar.Name;
                    }
                }
            }
            txtVeterinarFio.Text = sVeterinarFio;
        }
Esempio n. 3
0
        private void btnGuiltyEmloyeeSelect_Click(object sender, EventArgs e)
        {
            RFMCursorWait.Set(true);
            // ранее введеные значени¤
            OutputDocument oOutputDocumentTemp = new OutputDocument();

            oOutputDocumentTemp.FilterDateBeg = oOutputDocument.DateOutput.AddMonths(-1);
            oOutputDocumentTemp.FilterDateEnd = DateTime.Now.Date;
            oOutputDocumentTemp.FillData();
            if (oOutputDocumentTemp.ErrorNumber != 0 || oOutputDocumentTemp.MainTable == null)
            {
                RFMCursorWait.Set(false);
                RFMMessage.MessageBoxError("ќшибка при получении данных о расходных документах...");
                return;
            }
            if (oOutputDocument.MainTable.Rows.Count == 0)
            {
                RFMCursorWait.Set(false);
                RFMMessage.MessageBoxError("Ќет данных...");
                return;
            }

            DataView  dv = new DataView(oOutputDocumentTemp.MainTable, "GuiltyEmployees > ''", "GuiltyEmployees", DataViewRowState.CurrentRows);
            DataTable tdGuiltyEmployees = dv.ToTable(true, "GuiltyEmployees");

            /*
             * DataTable dtGuiltyEmployeesDistinct = new DataTable();
             * dtGuiltyEmployeesDistinct.Columns.Add("GuiltyEmployees");
             * System.Collections.Hashtable hash = new System.Collections.Hashtable();
             * foreach (DataRow row in oOutputDocumentTemp.MainTable.Rows)
             *      hash[row["GuiltyEmployees"]] = row["GuiltyEmployees"];
             * foreach (object name in hash.Values)
             *      dtGuiltyEmployeesDistinct.Rows.Add(name);
             * DataTable tdGuiltyEmployees = CopyTable(dtGuiltyEmployeesDistinct, "tdGuiltyEmployees", "GuiltyEmployees > ''", "GuiltyEmployees");
             */
            RFMCursorWait.Set(false);

            if (StartForm(new frmSelectID(this, tdGuiltyEmployees, "GuiltyEmployees", "¬иновник проблем", false)) == DialogResult.Yes)
            {
                if (_SelectedID == null)
                {
                    return;
                }
                txtGuiltyEmployees.Text = _SelectedText;
            }
            _SelectedID   = null;
            _SelectedText = "";

            return;
        }
        private bool grdOutputsDocuments_Restore()
        {
            grdOutputsDocuments.GetGridState();
            grdOutputsDocuments.DataSource = null;
            if (grdOutputs.Rows.Count == 0 ||
                oOutputCur.ID == null ||
                (grdOutputs.CurrentRow != null && grdOutputs.IsStatusRow(grdOutputs.CurrentRow.Index)))
            {
                return(true);
            }

            oOutputDocumentInOutput.FilterOutputsList = oOutputCur.ID.ToString();
            oOutputDocumentInOutput.FillData();
            grdOutputsDocuments.Restore(oOutputDocumentInOutput.MainTable);
            return(oOutputDocumentInOutput.ErrorNumber == 0);
        }
        private bool grdOutputsDocumentsInOutputs_Restore()
        {
            grdOutputsDocumentsInOutputs.GetGridState();
            grdOutputsDocumentsInOutputs.DataSource = null;
            if (grdOutputs.Rows.Count == 0 ||
                oOutputCur.ID == null ||
                (grdOutputs.CurrentRow != null && grdOutputs.IsStatusRow(grdOutputs.CurrentRow.Index)))
            {
                return(true);
            }

            DataRow o = ((DataRowView)grdOutputs.Rows[grdOutputs.CurrentRow.Index].DataBoundItem).Row;

            oOutputDocumentInOutput.FilterOutputsList = o["OldOutputID"].ToString();            //oOutputCur.ID.ToString();
            oOutputDocumentInOutput.FillData();
            grdOutputsDocumentsInOutputs.Restore(oOutputDocumentInOutput.MainTable);
            return(oOutputDocumentInOutput.ErrorNumber == 0);
        }
Esempio n. 6
0
        private bool grdOutputsDocuments_Restore()
        {
            RFMCursorWait.Set(true);
            RFMCursorWait.LockWindowUpdate(FindForm().Handle);

            oOutputDocumentCur.ClearOne();

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

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

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

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

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

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

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

            // рейс?
            if (optTripExists.Checked)
            {
                oOutputDocumentList.FilterTripExists = true;
            }
            if (optTripExistsNot.Checked)
            {
                oOutputDocumentList.FilterTripExists = false;
            }
            // задания на расход?
            if (optOutputExists.Checked)
            {
                oOutputDocumentList.FilterIsOutputExists = true;
            }
            if (optOutputExistsNot.Checked)
            {
                oOutputDocumentList.FilterIsOutputExists = false;
            }

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

            // подтверждение отгрузки
            if (optOutputsDocumentsIsConfirmedNot.Checked)
            {
                oOutputDocumentList.FilterIsConfirmed = false;
            }
            if (optOutputsDocumentsIsConfirmed.Checked)
            {
                oOutputDocumentList.FilterIsConfirmed = true;
            }

            // подтверждение доставки
            if (optOutputsDocumentsIsBroughtNot.Checked)
            {
                oOutputDocumentList.FilterIsBrought = false;
            }
            if (optOutputsDocumentsIsBrought.Checked)
            {
                oOutputDocumentList.FilterIsBrought = 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() + ",";
                    }
                }
                oOutputDocumentList.FilterTripsList = sTripsList;
            }
            if (numTripID.Value > 0)
            {
                if (oOutputDocumentList.FilterTripsList == null)
                {
                    oOutputDocumentList.FilterTripsList = Convert.ToInt32(numTripID.Value).ToString();
                }
                else
                {
                    oOutputDocumentList.FilterTripsList += Convert.ToInt32(numTripID.Value).ToString();
                }
            }

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

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

            grdOutputsDocumentsGoods.DataSource = null;

            grdOutputsDocuments.GetGridState();

            oOutputDocumentList.FillData();

            grdOutputsDocuments.IsLockRowChanged = true;
            grdOutputsDocuments.Restore(oOutputDocumentList.MainTable);
            tmrRestore.Enabled = true;

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

            return(oOutputDocumentList.ErrorNumber == 0);
        }
Esempio n. 7
0
        private void WarrantsAnalysis()
        {
            // тестирование доверенностей за период
            DateTime dDateBeg = DateTime.Now.Date;
            DateTime dDateEnd = DateTime.Now.Date.AddMonths(-1);

            if (StartForm(new frmDateRange(dDateBeg, dDateEnd)) == DialogResult.Yes)
            {
                if (GotParam[0] != null)
                {
                    dDateBeg = (DateTime)GotParam[0];
                }
                else
                {
                    dDateBeg = Convert.ToDateTime("01.01.1900");
                }

                if (GotParam[1] != null)
                {
                    dDateEnd = (DateTime)GotParam[1];
                }
                else
                {
                    dDateEnd = Convert.ToDateTime("31.12.2099");
                }
            }

            WarrantNumber oWarrantAnalysis = new WarrantNumber();

            oWarrantAnalysis.FilterDateBeg = dDateBeg;
            oWarrantAnalysis.FilterDateEnd = dDateEnd;
            oWarrantAnalysis.FillData();
            if (oWarrantAnalysis.ErrorNumber != 0 || oWarrantAnalysis.MainTable == null)
            {
                RFMMessage.MessageBoxError("Ошибка при анализе списка доверенностей...");
                return;
            }
            if (oWarrantAnalysis.MainTable.Rows.Count == 0)
            {
                RFMMessage.MessageBoxError("Нет данных о доверенностях за период...");
                return;
            }

            WaitOn(this);

            string sEol = Environment.NewLine;

            OutputDocument oOutputDocument = new OutputDocument();
            InputDocument  oInputDocument  = new InputDocument();

            DataTable dtWarrant = CopyTable(oWarrantAnalysis.MainTable, "dtWarrant", "", "PartnerSourceID, NumberInt, Number, DateIssue");

            string sText = "Анализ журнала выдачи доверенностей за период " + dDateBeg.ToString("dd.MM.yyyy") + " - " + dDateEnd.ToString("dd.MM.yyyy") +
                           sEol;

            int    nPartnerSourceID = -1;
            int    nNumberInt       = -1;
            int    nNumberIntOld    = -1;
            string sNumber          = "";
            bool   bOK = true;

            foreach (DataRow rW in dtWarrant.Rows)
            {
                oWarrantAnalysis.FillOne(rW);

                // новый партнер
                if (nPartnerSourceID != oWarrantAnalysis.PartnerSourceID)
                {
                    sText += sEol +
                             "Доверенности выданы фирмой: " + oWarrantAnalysis.PartnerSourceName +
                             sEol;
                    nPartnerSourceID = oWarrantAnalysis.PartnerSourceID;

                    nNumberInt    = -1;
                    nNumberIntOld = -1;
                    sNumber       = "";
                    bOK           = true;
                }

                nNumberInt = oWarrantAnalysis.NumberInt;
                sNumber    = oWarrantAnalysis.Number;

                // нумерация
                if (nNumberIntOld != -1)
                {
                    if (nNumberInt == nNumberIntOld)
                    {
                        sText += sNumber + "(" + nNumberInt.ToString().Trim() + "): доверенности с одинаковым порядковым номером" +
                                 sEol;
                        bOK = false;
                    }
                    if (nNumberInt != nNumberIntOld + 1)
                    {
                        sText += sNumber + " (" + nNumberIntOld.ToString() + " - " + nNumberInt.ToString().Trim() + "): пропуск в порядковых номерах доверенностей" +
                                 sEol;
                        bOK = false;
                    }
                }

                // заказы

                // заказ на отгрузку
                if (oWarrantAnalysis.OutputDocumentID.HasValue)
                {
                    oOutputDocument.ID = (int)oWarrantAnalysis.OutputDocumentID;
                    oOutputDocument.FillData();
                    if (oOutputDocument.MainTable.Rows.Count == 0)
                    {
                        sText += sNumber + ": не найден заказ на отгрузку с кодом " + oWarrantAnalysis.OutputDocumentID +
                                 sEol;
                        bOK = false;
                    }
                    else
                    {
                        oOutputDocument.FillOne();
                        // номера
                        if (oOutputDocument.WarrantNumber != sNumber)
                        {
                            sText += sNumber + ": не совпадают номера доверенностей в журнале и в заказе на отгрузку (" + oOutputDocument.WarrantNumber.ToString().Trim() + ")" +
                                     sEol;
                            bOK = false;
                        }
                        //
                        if (oOutputDocument.IsWarrantReturned && !oWarrantAnalysis.IsReturned)
                        {
                            sText += sNumber + ": в заказе на отгрузку доверенность возвращена, в журнале нет" +
                                     sEol;
                            bOK = false;
                        }
                        if (!oOutputDocument.IsWarrantReturned && oWarrantAnalysis.IsReturned)
                        {
                            sText += sNumber + ": в журнале доверенность возвращена, в заказе на отгрузку нет" +
                                     sEol;
                            bOK = false;
                        }
                        if (oWarrantAnalysis != null && oWarrantAnalysis.CurrencyID != null &&
                            (oOutputDocument.GetMoneyConfirmed != oWarrantAnalysis.Amount ||
                             oOutputDocument.GetCurrencyID != oWarrantAnalysis.CurrencyID))
                        {
                            sText += sNumber + ": сумма/валюта в журнале (" + ((decimal)oWarrantAnalysis.Amount).ToString("#####0.00") + oWarrantAnalysis.CurrencyName +
                                     ") и в заказе на отгрузку (" + oOutputDocument.GetMoneyConfirmed.ToString("#####0.00") + oOutputDocument.GetCurrencyName + ") не совпадают" +
                                     sEol;
                            bOK = false;
                        }
                    }
                }

                // заказ на поставку
                if (oWarrantAnalysis.InputDocumentID.HasValue)
                {
                    oInputDocument.ID = (int)oWarrantAnalysis.InputDocumentID;
                    oInputDocument.FillData();
                    if (oInputDocument.MainTable.Rows.Count != 1)
                    {
                        sText += sNumber + ": не найден заказ на поставку с кодом " + oWarrantAnalysis.InputDocumentID +
                                 sEol;
                        bOK = false;
                    }
                    else
                    {
                        oInputDocument.FillOne();
                        // номера
                        if (oInputDocument.WarrantNumber != sNumber)
                        {
                            sText += sNumber + ": не совпадают номера доверенностей в журнале и в заказе на поставку (" + oInputDocument.WarrantNumber.ToString().Trim() + ")" +
                                     sEol;
                            bOK = false;
                        }
                    }
                }
                // проверки законечены, переходим к следующей доверенности в списке

                nNumberIntOld = (int)rW["NumberInt"];
            }
            if (bOK)
            {
                sText += "OK" + sEol;
            }

            // анализ таблиц заказов

            // заказы на отгрузку
            bOK = true;
            oOutputDocument.FilterDateBeg = dDateBeg;
            oOutputDocument.FilterDateEnd = dDateEnd;
            oOutputDocument.FillData();
            if (oOutputDocument.ErrorNumber != 0 || oOutputDocument.MainTable == null)
            {
                RFMMessage.MessageBoxError("Ошибка при анализе списка заказов на отгрузку...");
            }
            else
            {
                if (oOutputDocument.MainTable.Rows.Count > 0)
                {
                    sText += sEol +
                             "Анализ списка заказов на отгрузку: " +
                             sEol;

                    string sOutputDocument = "";
                    foreach (DataRow rO in oOutputDocument.MainTable.Rows)
                    {
                        oOutputDocument.FillOne();
                        sOutputDocument = oOutputDocument.ID.ToString().Trim();
                        sNumber         = oOutputDocument.WarrantNumber;
                        if (sNumber == null)
                        {
                            sNumber = "";
                        }

                        // наличие доверенности
                        if (oOutputDocument.IsConfirmed)
                        {
                            if (oOutputDocument.PF_WarrantNeed && sNumber.Length == 0)
                            {
                                sText += sOutputDocument + ": не определен номер доверенности для заказа, где требуется доверенность" +
                                         sEol;
                                bOK = false;
                            }
                        }
                        if (!oOutputDocument.PF_WarrantNeed && sNumber.Length > 0)
                        {
                            sText += sOutputDocument + ": определен номер доверенности (" + sNumber + ") для заказа, где не требуется доверенность" +
                                     sEol;
                            bOK = false;
                        }

                        if (oOutputDocument.PF_WarrantNeed && sNumber.Length > 0)
                        {
                            oWarrantAnalysis.FilterOutputsDocumentsList = sOutputDocument;
                            oWarrantAnalysis.FillData();
                            if (oWarrantAnalysis.MainTable.Rows.Count == 0)
                            {
                                sText += sOutputDocument + ": в журнале не найдена доверенность (" + sNumber + ") для заказа" +
                                         sEol;
                                bOK = false;
                            }
                            if (oWarrantAnalysis.MainTable.Rows.Count > 1)
                            {
                                sText += sOutputDocument + ": в журнале найдено несколько доверенностей для заказа (" + sNumber + ")" +
                                         sEol;
                                bOK = false;
                            }

                            oWarrantAnalysis.FilterNumberContext      = sNumber;
                            oWarrantAnalysis.FilterPartnersSourceList = oOutputDocument.PartnerSourceID.ToString();
                            oWarrantAnalysis.FilterDateBeg            = oOutputDocument.DateOutput.AddDays(-10);
                            oWarrantAnalysis.FilterDateEnd            = oOutputDocument.DateOutput.AddDays(10);
                            oWarrantAnalysis.FillData();
                            if (oWarrantAnalysis.MainTable.Rows.Count == 0)
                            {
                                sText += sOutputDocument + ": в журнале не найдена доверенность по номеру (" + sNumber + "), указанному в заказе" +
                                         sEol;
                                bOK = false;
                            }
                            if (oWarrantAnalysis.MainTable.Rows.Count > 1)
                            {
                                sText += sOutputDocument + ": в журнале найдено несколько доверенностей по номеру (" + sNumber + "), указанному в заказе" +
                                         sEol;
                                bOK = false;
                            }

                            oWarrantAnalysis.FillOne();
                            if (oWarrantAnalysis.OutputDocumentID != oOutputDocument.ID)
                            {
                                sText += sOutputDocument + ": в журнале найдена доверенность по номеру (" + sNumber + "), но в ней указан другой заказ" +
                                         sEol;
                                bOK = false;
                            }
                            if (oWarrantAnalysis.PartnerSourceID != oOutputDocument.PartnerSourceID ||
                                oWarrantAnalysis.PartnerTargetID != oOutputDocument.PartnerTargetID)
                            {
                                sText += sOutputDocument + ": в журнале найдена доверенность по номеру (" + sNumber + "), но в ней указан другой клиент" +
                                         sEol;
                                bOK = false;
                            }
                            if (oWarrantAnalysis.Amount != null && oWarrantAnalysis.CurrencyID != null &&
                                ((decimal)oWarrantAnalysis.Amount != oOutputDocument.GetMoneyConfirmed ||
                                 (int)oWarrantAnalysis.CurrencyID != oOutputDocument.GetCurrencyID))
                            {
                                sText += sOutputDocument + ": в журнале найдена доверенность по номеру (" + sNumber + "), но в ней указана другая сумма" +
                                         sEol;
                                bOK = false;
                            }
                        }

                        if (!oOutputDocument.PF_WarrantNeed)
                        {
                            oWarrantAnalysis.FilterOutputsDocumentsList = sOutputDocument;
                            if (oWarrantAnalysis.MainTable.Rows.Count > 0)
                            {
                                sText += sOutputDocument + ": в журнале найдена доверенность (" + oWarrantAnalysis.MainTable.Rows[0]["Number"].ToString() + ") для заказа, для которого она не требуется" +
                                         sEol;
                                bOK = false;
                            }
                        }

                        // переходим к след.заказу
                    }
                    if (bOK)
                    {
                        sText += "OK";
                    }
                }
            }

            // здесь должны быть аналогичные проверки для заказов на поставку InputsDocuments
            bOK = true;

            // выводим отчет
            WaitOff(this);
            StartForm(new frmSysTextReport(sText));

            /*
             * string sFileName = ((RFMFormMain)Application.OpenForms[0]).UserInfo.UserLocPath + "WarrantsAnalysis.txt";
             * File.AppendAllText(sFileName, sText, Encoding.Default);
             * StartForm(new frmSysTextReport(true, sFileName));
             */
        }
        private bool FillOutputsDocuments_dt()
        {
            bool bOK = true;

            dt = null;

            oOutputDocument.FillData();
            if (oOutputDocument.ErrorNumber != 0 || oOutputDocument.MainTable == null)
            {
                bOK = false;
            }

            if (bOK)
            {
                oOutputDocument.FillTTNTableOutputsDocuments("-1");
                if (oOutputDocument.ErrorNumber != 0 || !oOutputDocument.DS.Tables.Contains("TableOutputsDocumentsTTN"))
                {
                    bOK = false;
                }
            }
            if (bOK)
            {
                dt = CopyTable(oOutputDocument.DS.Tables["TableOutputsDocumentsTTN"], "dt", "", "");

                DataTable dtOutputsDocuments = CopyTable(oOutputDocument.MainTable, "dtOutputsDocuments", "",
                                                         "PartnerDetailBayerID, PartnerDetailShipperID, BillNumber");
                int    nPartnerDetailBayerID       = 0;
                int    nPartnerDetailShipperID     = 0;
                string sOutputsDocumentsIDTempList = "";
                foreach (DataRow r in dtOutputsDocuments.Rows)
                {
                    if (((int)r["PartnerDetailBayerID"] != nPartnerDetailBayerID ||
                         (int)r["PartnerDetailShipperID"] != nPartnerDetailShipperID) &&
                        sOutputsDocumentsIDTempList.Length > 0)
                    {
                        oOutputDocument.FillTTNTableOutputsDocuments(sOutputsDocumentsIDTempList);
                        if (oOutputDocument.ErrorNumber != 0 || !oOutputDocument.DS.Tables.Contains("TableOutputsDocumentsTTN"))
                        {
                            bOK = false;
                            break;
                        }

                        dt.Merge(oOutputDocument.DS.Tables["TableOutputsDocumentsTTN"]);
                        sOutputsDocumentsIDTempList = "";
                    }

                    sOutputsDocumentsIDTempList += r["ID"].ToString() + ",";
                    nPartnerDetailBayerID        = (int)r["PartnerDetailBayerID"];
                    nPartnerDetailShipperID      = (int)r["PartnerDetailShipperID"];
                }
                if (sOutputsDocumentsIDTempList.Length > 0)
                {
                    oOutputDocument.FillTTNTableOutputsDocuments(sOutputsDocumentsIDTempList);
                    if (oOutputDocument.ErrorNumber != 0 || !oOutputDocument.DS.Tables.Contains("TableOutputsDocumentsTTN"))
                    {
                        bOK = false;
                    }
                    else
                    {
                        dt.Merge(oOutputDocument.DS.Tables["TableOutputsDocumentsTTN"]);
                    }
                }
            }
            return(bOK);
        }
        private bool dgvOutputsDocuments_Restore()
        {
            oOutputDocument.ClearError();
            oOutputDocument.FilterTripsList = nTripID.ToString();
            oOutputDocument.FillData();
            if (oOutputDocument.ErrorNumber == 0)
            {
                dt = oOutputDocument.MainTable;
                dt.Columns.Add("TimeBeg", Type.GetType("System.String"));
                dt.Columns.Add("TimeEnd", Type.GetType("System.String"));
                DataColumn dc = dt.Columns.Add("IsUnique", Type.GetType("System.Boolean"));
                dc.DefaultValue = false;

                DataRow dr;
                string  sDate;
                for (int nI = 0; nI < dt.Rows.Count; nI++)
                {
                    dr = dt.Rows[nI];

                    if (dr["DateBegFact"] == DBNull.Value)
                    {
                        sDate = "ddMMyyyy00:00";
                    }
                    else
                    {
                        sDate = (Convert.ToDateTime(dr["DateBegFact"])).ToString("ddMMyyyyHH:mm");
                    }

                    if (sDate.Length > 0)
                    {
                        dr["TimeBeg"] = sDate.Substring(8, 5);
                    }

                    if (dr["DateEndFact"] == DBNull.Value)
                    {
                        sDate = "ddMMyyyy00:00";
                    }
                    else
                    {
                        sDate = (Convert.ToDateTime(dr["DateEndFact"])).ToString("ddMMyyyyHH:mm");
                    }

                    if (sDate.Length > 0)
                    {
                        dr["TimeEnd"] = sDate.Substring(8, 5);
                    }
                }

                int         idMask = -1, idValue;
                DataRowView drv;
                dt.DefaultView.Sort = "PartnerTargetID";
                for (int i = 0; i < dt.DefaultView.Count; i++)
                {
                    drv     = dt.DefaultView[i];
                    idValue = (int)drv["PartnerTargetID"];
                    if (idMask != idValue)
                    {
                        drv["IsUnique"] = true;
                        idMask          = idValue;
                    }
                }
                dgvOutputsDocuments.Restore(dt);
                dgvOutputsDocuments.GridSource.Filter = "IsUnique";
                dgvOutputsDocuments.GridSource.Sort   = "ByOrder" + (oTrip.IsPostern ? " desc" : "") + ", PartnerTargetName";
            }
            return(oOutputDocument.ErrorNumber == 0);
        }
        private void FacturesAnalysis()
        {
            // тестирование счетов-фактур за период
            DateTime dDateBeg = DateTime.Now.Date;
            DateTime dDateEnd = DateTime.Now.Date.AddMonths(-1);

            if (StartForm(new frmDateRange(dDateBeg, dDateEnd)) == DialogResult.Yes)
            {
                if (GotParam[0] != null)
                {
                    dDateBeg = (DateTime)GotParam[0];
                }
                else
                {
                    dDateBeg = Convert.ToDateTime("01.01.1900");
                }

                if (GotParam[1] != null)
                {
                    dDateEnd = (DateTime)GotParam[1];
                }
                else
                {
                    dDateEnd = Convert.ToDateTime("31.12.2059");
                }
            }

            FactureNumber oFactureAnalysis = new FactureNumber();

            oFactureAnalysis.FilterDateBeg = dDateBeg;
            oFactureAnalysis.FilterDateEnd = dDateEnd;
            oFactureAnalysis.FillData();
            if (oFactureAnalysis.ErrorNumber != 0 || oFactureAnalysis.MainTable == null)
            {
                RFMMessage.MessageBoxError("Ошибка при анализе списка счетов-фактур...");
                return;
            }
            if (oFactureAnalysis.MainTable.Rows.Count == 0)
            {
                RFMMessage.MessageBoxError("Нет данных о счетах-фактурах за период...");
                return;
            }

            WaitOn(this);

            string sEol = Environment.NewLine;

            OutputDocument oOutputDocument = new OutputDocument();

            DataTable dtFacture = CopyTable(oFactureAnalysis.MainTable, "dtFacture", "", "PartnerSourceID, NumberInt, Number, DateIssue");

            string sText = "Анализ журнала выдачи счетов-фактур за период " + dDateBeg.ToString("dd.MM.yyyy") + " - " + dDateEnd.ToString("dd.MM.yyyy") +
                           sEol;

            int    nPartnerSourceID = -1;
            int    nNumberInt       = -1;
            int    nNumberIntOld    = -1;
            string sNumber          = "";
            bool   bOK = true;

            foreach (DataRow rW in dtFacture.Rows)
            {
                oFactureAnalysis.FillOne(rW);

                // новый партнер
                if (nPartnerSourceID != oFactureAnalysis.PartnerSourceID)
                {
                    sText += sEol +
                             "Cчета-фактуры выданы фирмой: " + oFactureAnalysis.PartnerSourceName +
                             sEol;
                    nPartnerSourceID = oFactureAnalysis.PartnerSourceID;

                    nNumberInt    = -1;
                    nNumberIntOld = -1;
                    sNumber       = "";
                    bOK           = true;
                }

                nNumberInt = oFactureAnalysis.NumberInt;
                sNumber    = oFactureAnalysis.Number;

                // нумерация
                if (nNumberIntOld != -1)
                {
                    if (nNumberInt == nNumberIntOld)
                    {
                        sText += sNumber + "(" + nNumberInt.ToString().Trim() + "): счета-фактуры с одинаковым порядковым номером" +
                                 sEol;
                        bOK = false;
                    }
                    if (nNumberInt != nNumberIntOld + 1)
                    {
                        sText += sNumber + " (" + nNumberIntOld.ToString() + " - " + nNumberInt.ToString().Trim() + "): пропуск в порядковых номерах счетов-фактур" +
                                 sEol;
                        bOK = false;
                    }
                }

                // заказы

                // заказ на отгрузку
                if (oFactureAnalysis.OutputDocumentID.HasValue)
                {
                    oOutputDocument.ID = (int)oFactureAnalysis.OutputDocumentID;
                    oOutputDocument.FillData();
                    if (oOutputDocument.MainTable.Rows.Count == 0)
                    {
                        sText += sNumber + ": не найден расходный документ с кодом " + oFactureAnalysis.OutputDocumentID +
                                 sEol;
                        bOK = false;
                    }
                    else
                    {
                        oOutputDocument.FillOne();
                        // номера
                        if (oOutputDocument.FactureNumber != sNumber)
                        {
                            sText += sNumber + ": не совпадают номера счетов-фактур в журнале и в расходном документе (" + oOutputDocument.FactureNumber.ToString().Trim() + ")" +
                                     sEol;
                            bOK = false;
                        }
                    }
                }

                // проверки законечены, переходим к следующей счета-фактуры в списке

                nNumberIntOld = (int)rW["NumberInt"];
            }
            if (bOK)
            {
                sText += "OK" + sEol;
            }

            // анализ таблицы заказов на отгрузку
            bOK = true;
            oOutputDocument.FilterDateBeg = dDateBeg;
            oOutputDocument.FilterDateEnd = dDateEnd;
            oOutputDocument.FillData();
            if (oOutputDocument.ErrorNumber != 0 || oOutputDocument.MainTable == null)
            {
                RFMMessage.MessageBoxError("Ошибка при анализе списка заказов на отгрузку...");
            }
            else
            {
                if (oOutputDocument.MainTable.Rows.Count > 0)
                {
                    sText += sEol +
                             "Анализ списка заказов на отгрузку: " +
                             sEol;

                    string sOutputDocument = "";
                    foreach (DataRow rO in oOutputDocument.MainTable.Rows)
                    {
                        oOutputDocument.FillOne();
                        sOutputDocument = oOutputDocument.ID.ToString().Trim();
                        sNumber         = oOutputDocument.FactureNumber;
                        if (sNumber == null)
                        {
                            sNumber = "";
                        }

                        // наличие счета-фактуры
                        if (oOutputDocument.IsConfirmed)
                        {
                            if (oOutputDocument.PF_FactureNeed && sNumber.Length == 0)
                            {
                                sText += sOutputDocument + ": не определен номер счета-фактуры для заказа, где требуется счет-фактура" +
                                         sEol;
                                bOK = false;
                            }
                        }
                        if (!oOutputDocument.PF_FactureNeed && sNumber.Length > 0)
                        {
                            sText += sOutputDocument + ": определен номер счета-фактуры (" + sNumber + ") для заказа, где не требуется счет-фактура" +
                                     sEol;
                            bOK = false;
                        }

                        if (oOutputDocument.PF_FactureNeed && sNumber.Length > 0)
                        {
                            oFactureAnalysis.FilterOutputsDocumentsList = sOutputDocument;
                            oFactureAnalysis.FillData();
                            if (oFactureAnalysis.MainTable.Rows.Count == 0)
                            {
                                sText += sOutputDocument + ": в журнале не найден счет-фактура (" + sNumber + ") для заказа" +
                                         sEol;
                                bOK = false;
                            }
                            if (oFactureAnalysis.MainTable.Rows.Count > 1)
                            {
                                sText += sOutputDocument + ": в журнале найдено несколько счетов-фактур для заказа (" + sNumber + ")" +
                                         sEol;
                                bOK = false;
                            }

                            oFactureAnalysis.FilterNumberContext      = sNumber;
                            oFactureAnalysis.FilterPartnersSourceList = oOutputDocument.PartnerSourceID.ToString();
                            oFactureAnalysis.FilterDateBeg            = oOutputDocument.DateOutput.AddDays(-10);
                            oFactureAnalysis.FilterDateEnd            = oOutputDocument.DateOutput.AddDays(10);
                            oFactureAnalysis.FillData();
                            if (oFactureAnalysis.MainTable.Rows.Count == 0)
                            {
                                sText += sOutputDocument + ": в журнале не найден счет-фактура по номеру (" + sNumber + "), указанному в заказе" +
                                         sEol;
                                bOK = false;
                            }
                            if (oFactureAnalysis.MainTable.Rows.Count > 1)
                            {
                                sText += sOutputDocument + ": в журнале найдено несколько счетов-фактур по номеру (" + sNumber + "), указанному в заказе" +
                                         sEol;
                                bOK = false;
                            }

                            oFactureAnalysis.FillOne();
                            if (oFactureAnalysis.OutputDocumentID != oOutputDocument.ID)
                            {
                                sText += sOutputDocument + ": в журнале найден счет-фактура по номеру (" + sNumber + "), но в нем указан другой заказ" +
                                         sEol;
                                bOK = false;
                            }
                            if (oFactureAnalysis.PartnerSourceID != oOutputDocument.PartnerSourceID ||
                                oFactureAnalysis.PartnerTargetID != oOutputDocument.PartnerTargetID)
                            {
                                sText += sOutputDocument + ": в журнале найден счет-фактура по номеру (" + sNumber + "), но в нем указан другой клиент" +
                                         sEol;
                                bOK = false;
                            }
                        }

                        if (!oOutputDocument.PF_FactureNeed)
                        {
                            oFactureAnalysis.FilterOutputsDocumentsList = sOutputDocument;
                            if (oFactureAnalysis.MainTable.Rows.Count > 0)
                            {
                                sText += sOutputDocument + ": в журнале найден счет-фактура (" + oFactureAnalysis.MainTable.Rows[0]["Number"].ToString() + ") для заказа, для которого он не требуется" +
                                         sEol;
                                bOK = false;
                            }
                        }

                        // переходим к след.заказу
                    }
                    if (bOK)
                    {
                        sText += "OK";
                    }
                }
            }

            // здесь должны быть аналогичные проверки для заказов на поставку
            bOK = true;

            // выводим отчет
            WaitOff(this);
            StartForm(new frmSysTextReport(sText));
        }