Exemplo n.º 1
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string ordersDate   = txtOrdersDate.Text;
            string paymentMode  = drpPaymentMode.SelectedValue;
            string supplierName = this.SupplierName.Value;
            //string supplierId = drpSupplierId.SelectedValue;
            string supplierId  = string.Empty;
            string contactId   = drpContactId.SelectedValue;
            string orderNumber = string.Empty;
            string remark      = txtRemark.Text;
            string sql         = string.Empty;
            string error       = string.Empty;
            string orderType   = drpOrderType.SelectedValue;
            string htNumber    = txtHTNumber.Text.Trim();


            string checkSql = string.Format(@"
select SupplierId from SupplierInfo where SupplierName='{0}' ", supplierName);

            supplierId = SqlHelper.GetScalar(checkSql);
            if (string.IsNullOrEmpty(supplierId))
            {
                ToolCode.Tool.GetMasterLabel(this.Page, "lbSubmit").Text = "不存在该供应商名称,请重新输入";
                return;
            }

            if (btnSubmit.Text.Equals("添加"))
            {
                orderNumber = txtOrderNumber.Text.Trim();

                if (string.IsNullOrEmpty(orderNumber))
                {
                    orderNumber = "CG" + DateTime.Now.ToString("yyyyMMddHHmmss");
                }
                if (CheckHas(orderNumber))
                {
                    ToolCode.Tool.GetMasterLabel(this.Page, "lbSubmit").Text = "已存在该采购订单号!请重新输入";
                    return;
                }

                sql = string.Format(@" 
insert into CertificateOrders (OrdersNumber,OrdersDate,PaymentMode,SupplierId
,ContactId,OrderStatus,CreateTime ,Remark,OrderType ,HTNumber)
values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}') ", orderNumber, ordersDate
                                    , paymentMode, supplierId, contactId, "未完成", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), remark, orderType, htNumber);


                bool result = SqlHelper.ExecuteSql(sql, ref error);
                ToolCode.Tool.GetMasterLabel(this.Page, "lbSubmit").Text = result == true ? "添加成功" : "添加失败!原因:" + error;
                if (result)
                {
                    Tool.WriteLog(Tool.LogType.Operating, "增加采购单信息" + orderNumber, "增加成功");
                    ToolManager.CloseCurrentPage();
                    return;
                }
                else
                {
                    Tool.WriteLog(Tool.LogType.Operating, "增加采购单信息" + orderNumber, "增加失败!原因:" + error);
                    return;
                }
            }
            else
            {
                string ordersNumber = ToolManager.GetQueryString("OrdersNumber");
                if (!CheckHas(ordersNumber))
                {
                    Response.Write("该采购订单不存在!");
                    Response.End();
                    return;
                }
                sql = string.Format(@"update CertificateOrders set OrdersDate='{0}'
,PaymentMode='{1}',SupplierId='{2}',ContactId='{3}',Remark ='{4}',OrderType='{6}',HTNumber='{7}' where OrdersNumber='{5}'
", ordersDate, paymentMode, supplierId, contactId, remark, ordersNumber, orderType, htNumber);
                bool result = SqlHelper.ExecuteSql(sql, ref error);
                ToolCode.Tool.GetMasterLabel(this.Page, "lbSubmit").Text = result == true ? "修改成功" : "修改失败!原因:" + error;
                if (result)
                {
                    Tool.WriteLog(Tool.LogType.Operating, "编辑采购单信息" + ordersNumber, "编辑成功");
                    Response.Write(ToolManager.GetClosePageJS());
                    Response.End();
                    return;
                }
                else
                {
                    Tool.WriteLog(Tool.LogType.Operating, "编辑采购单信息" + ordersNumber, "编辑失败!原因" + error);
                    return;
                }
            }
        }