protected void btnSave_Click(object sender, EventArgs e) { if (Convert.ToDateTime(myFunc.SaveDate(dpDCDate.Text)).Date > Convert.ToDateTime(DateTime.Now.Date.ToString("yyyy-MM-dd")).Date) { lblMSG.Text = "DC Date should not greater then current date."; PopupControlMSG.ShowOnPageLoad = true; return; //myFunc.UserMsg(lblMSG, Color.Red, "Date should not greater then current date"); } if (Convert.ToDateTime(myFunc.SaveDate(dpDCDate.Text)).Date < Convert.ToDateTime(myFunc.SaveDate(dpPODate.Text)).Date) { lblMSG.Text = "DC Date should not less then PO Date"; PopupControlMSG.ShowOnPageLoad = true; return; } if (txtVendorDCNo.Text == "") { lblMSG.Text = "Please enter vendor DC Number"; //PopupControlMSG.ShowOnPageLoad = true; return; } string newDCNo = ""; if (ddDCNumber.Text == "" && this.Session["DCNumber"].ToString() == "") { newDCNo = myFunc.GetNewDCNumber(this.Session["DealerCode"].ToString()); } else { if (ddDCNumber.Text != "") { newDCNo = ddDCNumber.Text; } else { newDCNo = this.Session["DCNumber"].ToString(); } } string sql = ""; if (myFunc.isDCExist(newDCNo)) { sql = "UPDATE DCMASTER SET VendorDCNo='" + txtVendorDCNo.Text + "',Remarks='" + txtRemarks.Text + "' where DCNo='" + newDCNo + "'"; } else { sql = "INSERT INTO DCMASTER (DealerCode,DCNo,DCDate,PONo,VendorDCNo,VendorCode,Remarks,DelFlag,UpdUser,UpdDate,UpdTime)"; sql += " VALUES ('" + this.Session["DealerCode"].ToString() + "','" + newDCNo + "','" + dpDCDate.Date.ToString("yyyy/MM/dd") + "','" + ddPONumber.Text + "','"; sql += txtVendorDCNo.Text.Trim() + "','" + txtVendorCode.Text + "','" + txtRemarks.Text.Trim() + "','N','" + this.Session["UserID"].ToString() + "',"; sql += "CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)"; } DataTable dt = myFunc.GetData(sql); // save detail RemoveQTYFromPO(newDCNo, "-"); sql = "delete from DCDetail where DCNo='" + newDCNo + "'"; myFunc.GetData(sql); DataSet ds = (DataSet)Session["DCDataSet"]; dt = ds.Tables[0]; string ItemCode = ""; string slct = ""; for (int i = 0; i < dt.Rows.Count; i++) { slct = dt.Rows[i]["Selected"].ToString(); if (slct == "True") { ItemCode = myFunc.GetItemCodeByPartItemNo(dt.Rows[i]["PartItemNo"].ToString()); sql = "INSERT INTO DCDetail (DealerCode, DCNo, ItemCode, PONo, POQty, BalQty, DCQty)"; sql += " VALUES('" + this.Session["DealerCode"].ToString() + "','" + newDCNo + "','" + ItemCode + "','" + ddPONumber.Text.Trim() + "','"; sql += dt.Rows[i]["POQuantity"].ToString() + "','" + dt.Rows[i]["BalanceQuantity"].ToString() + "','" + dt.Rows[i]["DCQuantity"].ToString() + "')"; myFunc.GetData(sql); } } RemoveQTYFromPO(newDCNo, "+"); lblMSG.Text = newDCNo + " has been saved"; PopupControlMSG.ShowOnPageLoad = true; btnClear_Click(btnClear, EventArgs.Empty); //ddDCNumber.Text = newDCNo; }