Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            oOutputDocument.ClearError();

            if (!bCarry)
            {
                // дл¤ заказа в целом
                if (pnlOutputDocument.Enabled)
                {
                    // причина
                    if (cboOutputDocumentFailReason.SelectedValue == null || cboOutputDocumentFailReason.SelectedIndex < 0)
                    {
                        RFMMessage.MessageBoxError("Ќе указана причина проблемы дл¤ документа в целом...");
                        cboOutputDocumentFailReason.Select();
                        return;
                    }
                    oOutputDocument.ChangeOutputDocumentFailReason(nID, (int)cboOutputDocumentFailReason.SelectedValue);

                    // виновник-текст
                    if (txtGuiltyEmployees.Text.Trim().Length > 0)
                    {
                        oOutputDocument.SetGuiltyEmployees(nID, null, txtGuiltyEmployees.Text.Trim(), chkIsDriverFoul.Checked);
                    }
                    else
                    {
                        // сохран¤ем пустое значение виновника-текста
                        if (oOutputDocument.GuiltyEmployees != null && oOutputDocument.GuiltyEmployees.Length > 0)
                        {
                            // очистка виновника-текста
                            if (RFMMessage.MessageBoxYesNo("ќчистить данные о виновниках проблемы дл¤ документа в целом?") == DialogResult.Yes)
                            {
                                oOutputDocument.SetGuiltyEmployees(nID, null, "", false);
                            }
                        }
                    }
                }

                // дл¤ товаров
                if (pnlOutputDocumentGoods.Enabled)
                {
                    // провер¤ем указание причины
                    foreach (DataRow rGood in dt.Rows)
                    {
                        if ((decimal)rGood["QntConfirmed"] != (decimal)rGood["QntWished"])
                        {
                            if (rGood["ReturnReasonID"] == null || rGood["ReturnReasonID"] == DBNull.Value)
                            {
                                RFMMessage.MessageBoxError("Ќе указана причина несоответстви¤ отгруженного и доставленного количества дл¤ товара\n" +
                                                           rGood["GoodName"].ToString() + "...");
                                int nGridPosition = ((RFMBindingSource)grdOutputsDocumentsGoods.GridSource).Find("ID", (int)rGood["ID"]);
                                if (nGridPosition >= 0)
                                {
                                    grdOutputsDocumentsGoods.GridSource.Position = nGridPosition;
                                }
                                return;
                            }
                        }
                    }

                    foreach (DataRow rGood in dt.Rows)
                    {
                        int nOutputDocumentGoodID = (int)rGood["ID"];
                        // причина
                        if (rGood["ReturnReasonID"] != null && rGood["ReturnReasonID"] != DBNull.Value)
                        {
                            oOutputDocument.ChangeOutputDocumentGoodReturnReason(nOutputDocumentGoodID, (int)rGood["ReturnReasonID"]);
                            if (oOutputDocument.ErrorNumber != 0)
                            {
                                return;
                            }
                        }
                        // виновник-текст
                        oOutputDocument.SetGuiltyEmployees(null, nOutputDocumentGoodID, rGood["GuiltyEmployees"].ToString(), false);
                        if (oOutputDocument.ErrorNumber != 0)
                        {
                            return;
                        }
                    }
                }
            }
            else
            {
                // дл¤ переноса
                if (cboOutputDocumentFailReason.SelectedValue == null || cboOutputDocumentFailReason.SelectedIndex < 0)
                {
                    RFMMessage.MessageBoxError("Ќе указана причина проблемы (переноса) заказа...");
                    cboOutputDocumentFailReason.Select();
                    return;
                }
                oOutputDocument.ChangeOutputDocumentCarryFailReasonGuiltyEmployees(nCarryID, (int)cboOutputDocumentFailReason.SelectedValue, txtGuiltyEmployees.Text.Trim(), chkIsDriverFoul.Checked);
            }

            if (oOutputDocument.ErrorNumber == 0)
            {
                DialogResult = DialogResult.Yes;
                Dispose();
            }
        }