protected void glFromItemPartNo_TextChanged(object sender, EventArgs e)
 {
     lblErr.Text = "";
     if (glFromItemPartNo.Text == "")
     {
         txtPartItemDescFrom.Text = "";
         return;
     }
     txtPartItemDescFrom.Text = myFunc.GetItemDescByItemCode(myFunc.GetItemCodeByPartItemNo(glFromItemPartNo.Text));
 }
Exemple #2
0
        public void btnSave_Click(object sender, EventArgs e)
        {
            if (!sec.UserRight("2542", "002"))
            {
                Response.Redirect("~/Test.aspx");
            }

            if (Convert.ToDateTime(myFunc.SaveDate(txtDCDate.Text)).Date > Convert.ToDateTime(DateTime.Now.Date.ToString("yyyy-MM-dd")).Date)
            {
                myFunc.UserMsg(lblMessage, Color.Red, "DC Date should not greater then current date.");
                return;
            }

            if (Convert.ToDateTime(myFunc.SaveDate(txtDCDate.Text)).Date < Convert.ToDateTime(myFunc.SaveDate(txtPODate.Text)).Date)
            {
                myFunc.UserMsg(lblMessage, Color.Red, "DC Date should not less then PO Date.");
                return;
            }
            if (txtVendorDCn0.Text == "")
            {
                myFunc.UserMsg(lblMessage, Color.Red, "Please enter vendor DC Number.");
                return;
            }

            if (gv_DC.Rows.Count == 0)
            {
                lblMessage.ForeColor = Color.Red;
                lblMessage.Text      = "Please Select PO Number.";
                return;
            }

            string newDCNo = "";

            if (ddlDCno.SelectedValue == "0")
            {
                //newDCNo = myFunc.GetNewDCNumber(this.Session["DealerCode"].ToString());
                newDCNo = myFunc.AutoGen("DCMaster", "DCNo", DateTime.Parse(DateTime.Now.ToShortDateString()).ToString("dd/MM/yyyy"));
            }
            else
            {
                if (ddlDCno.SelectedValue != "")
                {
                    if (!sec.UserRight("2542", "003"))
                    {
                        Response.Redirect("~/Test.aspx");
                    }
                    newDCNo = ddlDCno.SelectedValue;
                }
                else
                {
                    newDCNo = this.Session["DCNumber"].ToString();
                }
            }
            string sql = "";

            if (myFunc.isDCExist(newDCNo, Session["DealerCode"].ToString()))
            {
                sql = "UPDATE DCMaster SET VendorDCNo='" + txtVendorDCn0.Text + "',Remarks='" + txtRemarks.Text + "' where DCNo='" + newDCNo + "' and DealerCode = '" + Session["DealerCode"].ToString() + "'";
            }
            else
            {
                sql  = "INSERT INTO DCMaster (DealerCode,DCNo,DCDate,PONo,VendorDCNo,VendorCode,Remarks,DelFlag,UpdUser,UpdDate,UpdTime)";
                sql += " VALUES ('" + this.Session["DealerCode"].ToString() + "','" + newDCNo + "','" + myFunc.SaveDate(txtDCDate.Text) + "','" + ddlPONo.SelectedValue + "','";
                sql += txtVendorDCn0.Text.Trim() + "','" + txtVendor.Text + "','" + txtRemarks.Text.Trim() + "','N','" + this.Session["UserID"].ToString() + "',";
                sql += "CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)";
            }
            try
            {
                int slct = 0;

                if (ObjTrans.BeginTransaction(ref Trans) == true)
                {
                    myFunc.ExecuteQuery_NonQuery(sql, Trans);
                    // save detail

                    RemoveQTYFromPO(newDCNo, "-");
                    sql = "delete from DCDetail where DCNo ='" + newDCNo + "' and DealerCode = '" + Session["DealerCode"].ToString() + "'";
                    myFunc.ExecuteQuery_NonQuery(sql, Trans);

                    DataTable dt       = (DataTable)Session["DCTable"];
                    string    ItemCode = "";

                    int i = 0;

                    foreach (GridViewRow row in gv_DC.Rows)
                    {
                        CheckBox chkSelect = (CheckBox)row.FindControl("cbSelect");

                        if (chkSelect.Checked)
                        {
                            ItemCode = myFunc.GetItemCodeByPartItemNo(dt.Rows[i]["PartItemNo"].ToString(), Session["DealerCode"].ToString());
                            sql      = "INSERT INTO DCDetail (DealerCode, DCNo, ItemCode, PONo, POQty, BalQty, DCQty)";
                            sql     += " VALUES('" + this.Session["DealerCode"].ToString() + "','" + newDCNo + "','" + ItemCode + "','" + ddlPONo.SelectedValue + "','";
                            sql     += dt.Rows[i]["POQuantity"].ToString() + "','" + dt.Rows[i]["BalanceQuantity"].ToString() + "','" + dt.Rows[i]["DCQuantity"].ToString() + "')";
                            myFunc.ExecuteQuery_NonQuery(sql, Trans);
                            slct++;
                        }
                        i++;
                    }
                }
                else
                {
                    ObjTrans.RollBackTransaction(ref Trans);
                }
                //Commented By Uzair
                //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 + "','" + ddlPONo.SelectedValue + "','";
                //        sql += dt.Rows[i]["POQuantity"].ToString() + "','" + dt.Rows[i]["BalanceQuantity"].ToString() + "','" + dt.Rows[i]["DCQuantity"].ToString() + "')";
                //        myFunc.GetData(sql);
                //    }
                //}
                if (slct > 0)
                {
                    ObjTrans.CommittTransaction(ref Trans);
                    RemoveQTYFromPO(newDCNo, "+");
                    lblMessage.ForeColor = Color.Green;
                    lblMessage.Text      = newDCNo + " has been saved";
                    ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('Record Saved,Updated Successfully: " + newDCNo + "')", true);
                    ClearAll();
                    lOADddl();
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "Savealert()", true);
                }
                else
                {
                    ObjTrans.RollBackTransaction(ref Trans);
                    lblMessage.ForeColor = Color.Red;
                    lblMessage.Text      = "At least one row should be selected";
                }
            }
            catch (Exception)
            {
                ObjTrans.RollBackTransaction(ref Trans);
            }
            //ddDCNumber.Text = newDCNo;
        }
        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;
        }