Exemplo n.º 1
0
        void IOrder.Save()
        {
            try
            {
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
                //
                if (txt_sup.Text.Trim().Contains("/") == false)
                {
                    MsgForm.ShowFrom("供应商必填!");
                    return;
                }
                if (txtbranch.Text.Trim().Contains("/") == false)
                {
                    MsgForm.ShowFrom("机构必填!");
                    return;
                }
                if (txtoper_date.Text.Trim() == "")
                {
                    MsgForm.ShowFrom("单据日期必填!");
                    return;
                }

                co_t_order_main         ord   = new co_t_order_main();
                List <co_t_order_child> lines = new List <co_t_order_child>();
                ord.sheet_no     = txtsheet_no.Text.Trim();
                ord.branch_no    = txtbranch.Text.Trim().Split('/')[0];
                ord.sup_no       = txt_sup.Text.Trim().Split('/')[0];
                ord.coin_code    = "RMB";
                ord.paid_amount  = 0;
                ord.oper_date    = Helper.Conv.ToDateTime(txtoper_date.Text.Trim());
                ord.oper_id      = txtoper_man.Text.Split('/')[0];
                ord.order_man    = txt_order_man.Text.Split('/')[0];
                ord.trans_no     = "S";
                ord.order_status = "0";
                ord.sale_way     = "A";
                ord.p_sheet_no   = "";
                ord.approve_flag = "0";
                ord.other1       = "";
                ord.cm_branch    = "00";
                ord.approve_man  = txtapprove_man.Text.Split('/')[0];
                ord.approve_date = System.DateTime.MinValue;
                ord.num1         = 0;
                ord.num2         = 0;
                ord.num3         = 0;
                ord.valid_date   = txt_valid_date.Text.ToDateTime();
                ord.memo         = txt_memo.Text;

                int     flag      = 0;
                int     index     = 0;
                decimal total_amt = 0;
                foreach (DataRow row in editGrid1.DataSource.Rows)
                {
                    ++index;
                    if (row["item_no"].ToString() != "")
                    {
                        co_t_order_child line = new co_t_order_child();
                        lines.Add(line);
                        line.sheet_no    = ord.sheet_no;
                        line.item_no     = row["item_no"].ToString();
                        line.unit_no     = row["unit_no"].ToString();
                        line.barcode     = row["barcode"].ToString();
                        line.unit_factor = 1;
                        line.discount    = row["discount"].ToDecimal();
                        line.in_price    = Helper.Conv.ToDecimal(row["in_price"].ToString());
                        line.order_qnty  = Helper.Conv.ToDecimal(row["order_qnty"].ToString());
                        line.sub_amount  = Helper.Conv.ToDecimal(row["sub_amount"].ToString());
                        line.discount    = 1;
                        line.other1      = row["other1"].ToString();
                        line.other2      = "";
                        line.voucher_no  = "";
                        line.sheet_sort  = index;
                        line.num1        = 0;
                        line.num2        = 0;
                        line.num3        = 0;
                        line.packqty     = 0;
                        line.sgqty       = 0;
                        flag             = 1;
                        total_amt       += line.order_qnty * line.in_price;
                    }
                }
                if (flag == 0)
                {
                    MsgForm.ShowFrom("请输入表单明细");
                    return;
                }
                ord.total_amount = total_amt;

                IBLL.IInOutBLL bll = new BLL.InOutBLL();
                if (runType == 1)
                {
                    var sheet_no = "";
                    bll.AddCGOrder(ord, lines, out sheet_no);
                    IOrder ins = this;
                    ins.ShowOrder(sheet_no);
                }
                else if (runType == 2)
                {
                    bll.ChangeCGOrder(ord, lines);
                    IOrder ins = this;
                    ins.ShowOrder(ord.sheet_no);
                }

                Dictionary <string, object> dic = this.Tag as Dictionary <string, object>;
                this.Tag = Helper.Conv.ControlsAdds(this, dic);

                IBLL.ISys sys       = new BLL.SysBLL();
                string    isApprove = sys.Read("approve_at_ones");
                if ("1".Equals(isApprove))
                {
                    if (YesNoForm.ShowFrom("保存成功!是否立即审核") == DialogResult.Yes)
                    {
                        tsbCheck_Click(new object(), new EventArgs());
                    }
                }
            }
            catch (Exception ex)
            {
                Helper.LogHelper.writeLog("frmCGOrder->Save()", ex.ToString(), txtsheet_no.Text);
                MsgForm.ShowFrom("采购订单保存异常[" + ex.Message + "]");
            }
            finally
            {
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
            }
        }