Exemplo n.º 1
0
        private void simpleButton1_Click(object sender, System.EventArgs e)
        {
            DataRow dr = gridView1.GetDataRow(gridView1.FocusedRowHandle);

            try
            {
                if (dr.Table.Rows.Count==0)
                {
                    MessageBox.Show("Not allowed to Save Empty Entries","Warning");
                    return;
                }
            }
            catch (Exception ex)
            {
                return;
            }

            SqlConnection sqlcon = new SqlConnection(SqlHelperUtils.connectionString);
            sqlcon.Open();

            SqlTransaction trans = sqlcon.BeginTransaction();

            if(this.lkBranchTo.EditValue.ToString()=="Select Branch" | this.lkBranchTo.EditValue.ToString()=="")
            {
                ACMS.Utils.UI.ShowErrorMessage(this,"Please select valid Branch Code","Error");

            }
            else if(canSave)
            {
                ACMSLogic.InterBranchTransfer.InterBranchTransfer ibts = new ACMSLogic.InterBranchTransfer.InterBranchTransfer();
                int nIBTNo = 0;

                //Hashtable htIBT = new Hashtable();
                //htint
                if(isEdit)
                {

                    if(!ibts.UpdateIBT(trans,DateTime.Now,this.terminalUser.Branch.Id,this.lkBranchTo.EditValue.ToString(),0,this.employee.Id,DateTime.Now,this.txtRemarks.Text,this.nIBTNo))
                    {
                        trans.Rollback();
                        sqlcon.Close();
                        UI.ShowErrorMessage(this,"RollBack Transaction - Update IBT","Error");
                        return;
                    }
                    ACMSLogic.AuditTrail.AuditTrail audit = new ACMSLogic.AuditTrail.AuditTrail();
                    audit.SaveAuditTrail(trans,8,"Update IBT "+this.nIBTNo,"IBT",this.employee.Id);

                }
                else
                {
                    nIBTNo = ibts.SaveIBT(trans,DateTime.Now,this.terminalUser.Branch.Id,this.lkBranchTo.EditValue.ToString(),0,this.employee.Id,DateTime.Now,this.txtRemarks.Text);
                    ACMSLogic.AuditTrail.AuditTrail audit = new ACMSLogic.AuditTrail.AuditTrail();
                    audit.SaveAuditTrail(trans,8,"Save IBT "+this.nIBTNo,"IBT",this.employee.Id);

                    #region nHibernate Code
            //					//DateTime
            //					htIBT.Add("dtDate",DateTime.Now);
            //					//int
            //					//Status 0 - Pending Request
            //					htIBT.Add("nStatusID",0);
            //					//DateTime
            //					htIBT.Add("dtLastEditDate",DateTime.Now);
            //					//string
            //					htIBT.Add("strRemarks",this.txtRemarks.Text);
            //
            //					//string
            //					htIBT.Add("Branch_strBranchCodeFrom",this.terminalUser.Branch.Id);
            //
            //					//string
            //					htIBT.Add("Branch_strBranchCodeTo",this.lkBranchTo.EditValue);
            //
            //					//int
            //					htIBT.Add("Employee_nEmployeeID",this.employee.Id);
                    #endregion
                }
                ArrayList ibtEntryList = new ArrayList();

                ArrayList ibtProductTransferList = new ArrayList();

                DevExpress.XtraGrid.Columns.GridColumn col1 = gridView1.Columns.ColumnByFieldName("strItemCode");
                DevExpress.XtraGrid.Columns.GridColumn col2 = gridView1.Columns.ColumnByFieldName("nQuantity");
                DevExpress.XtraGrid.Columns.GridColumn col3 = gridView1.Columns.ColumnByFieldName("nEntryID");
                for(int i=0;i<this.gridView1.DataRowCount;i++)
                {

                    object cellValue1 = gridView1.GetRowCellValue(i, col1);
                    object cellValue2 = gridView1.GetRowCellValue(i, col2);
                    object cellValue3 = null;

                    IBTProductTransfer ibt;
                    int nEntryID = 0;

                    string strProductCode = cellValue1.ToString();
                    int quantity = Convert.ToInt32(cellValue2.ToString());

                    if(isEdit)
                    {
                        cellValue3 = gridView1.GetRowCellValue(i, col3);
                        nEntryID = Convert.ToInt32(cellValue3);
                        ibt = new IBTProductTransfer(strProductCode,quantity,nEntryID);
                    }
                    else
                    {
                        ibt = new IBTProductTransfer(strProductCode,quantity);
                    }

                    if(ibtProductTransferList.Count==0)
                    {
                        ibtProductTransferList.Add(ibt);
                    }
                    else
                    {
                        bool duplicate=false;
                        for(int _i=0;_i<ibtProductTransferList.Count;_i++)
                        {
                            IBTProductTransfer _ibt = ibtProductTransferList[_i] as IBTProductTransfer;

                            if(strProductCode==_ibt.StrProductCode)
                            {
                                _ibt.Quantity=_ibt.Quantity+quantity;
                                duplicate=true;
                            }
                        }

                        if(!duplicate)
                            ibtProductTransferList.Add(ibt);
                    }
                }

                //Variable Hashtable
                //bool doubleCheckCanSave=true;

                if(isEdit)
                {

                    foreach(IBTProductTransfer ibt in ibtProductTransferList)
                    {

                        if(!ibts.UpdateIBTEntries(trans,NIBTNo,ibt.StrProductCode,ibt.Quantity,this.terminalUser.Branch.Id,ibt.NEntryID))
                        {
                            trans.Rollback();
                            sqlcon.Close();
                            UI.ShowErrorMessage(this,"RollBack Transaction - Update IBTEntries","Error");
                            return;
                        }
                    }
                    ACMSLogic.AuditTrail.AuditTrail audit = new ACMSLogic.AuditTrail.AuditTrail();
                    audit.SaveAuditTrail(trans,8,"Update IBTEntries "+NIBTNo,"IBTEntries",this.employee.Id);

                    UI.ShowMessage(this,"Record Has Been Updated");
                }
                else
                {
                    if(nIBTNo!=0)
                    {
                        foreach(IBTProductTransfer ibt in ibtProductTransferList)
                        {
                            if(!ibts.SaveIBTEntries(trans,nIBTNo,ibt.StrProductCode,ibt.Quantity,this.terminalUser.Branch.Id))
                            {
                                trans.Rollback();
                                sqlcon.Close();
                                UI.ShowErrorMessage(this,"RollBack Transaction - Update StockRequestEntries","Error");
                                return;
                            }
                            #region nHibernate Code
                            //					Hashtable htIBTEntries = new Hashtable();
                            //
                            //					htIBTEntries.Add("strItemCode",ibt.StrProductCode);
                            //					//int
                            //					htIBTEntries.Add("nQuantity",ibt.Quantity);
                            //
                            //					Rp.ProductRepository pr = new Rp.ProductRepository();
                            //
                            //					Acms.Core.Domain.ProductInventory pi = pr.CheckQuantityAvailable(ibt.StrProductCode,this.terminalUser.Branch.Id);
                            //					if(pi!=null)
                            //					{
                            //
                            //						if(!pi.IsValidQuantityRequest(ibt.Quantity))
                            //						{
                            //							doubleCheckCanSave=false;
                            //							//return;
                            //						}
                            //					}
                            //
                            //					ibtEntryList.Add(htIBTEntries);
                            #endregion
                        }
                        ACMSLogic.AuditTrail.AuditTrail audit = new ACMSLogic.AuditTrail.AuditTrail();
                        audit.SaveAuditTrail(trans,8,"Save IBTEntries "+NIBTNo,"IBTEntries",this.employee.Id);

                    }
                    UI.ShowMessage(this,"Record Has Been Saved");
                }

            }

            trans.Commit();
            sqlcon.Close();
            this.DialogResult = DialogResult.OK;
        }
Exemplo n.º 2
0
        private void simpleButton1_Click(object sender, System.EventArgs e)
        {
            DataRow dr = gridView1.GetDataRow(gridView1.FocusedRowHandle);

            try
            {
                if (dr.Table.Rows.Count == 0)
                {
                    MessageBox.Show("Not allowed to Save Empty Entries", "Warning");
                    return;
                }
            }
            catch (Exception ex)
            {
                return;
            }

            SqlConnection sqlcon = new SqlConnection(SqlHelperUtils.connectionString);

            sqlcon.Open();

            SqlTransaction trans = sqlcon.BeginTransaction();

            if (this.lkBranchTo.EditValue.ToString() == "Select Branch" | this.lkBranchTo.EditValue.ToString() == "")
            {
                ACMS.Utils.UI.ShowErrorMessage(this, "Please select valid Branch Code", "Error");
            }
            else if (canSave)
            {
                ACMSLogic.InterBranchTransfer.InterBranchTransfer ibts = new ACMSLogic.InterBranchTransfer.InterBranchTransfer();
                int nIBTNo = 0;

                //Hashtable htIBT = new Hashtable();
                //htint
                if (isEdit)
                {
                    if (!ibts.UpdateIBT(trans, DateTime.Now, this.terminalUser.Branch.Id, this.lkBranchTo.EditValue.ToString(), 0, this.employee.Id, DateTime.Now, this.txtRemarks.Text, this.nIBTNo))
                    {
                        trans.Rollback();
                        sqlcon.Close();
                        UI.ShowErrorMessage(this, "RollBack Transaction - Update IBT", "Error");
                        return;
                    }
                    ACMSLogic.AuditTrail.AuditTrail audit = new ACMSLogic.AuditTrail.AuditTrail();
                    audit.SaveAuditTrail(trans, 8, "Update IBT " + this.nIBTNo, "IBT", this.employee.Id);
                }
                else
                {
                    nIBTNo = ibts.SaveIBT(trans, DateTime.Now, this.terminalUser.Branch.Id, this.lkBranchTo.EditValue.ToString(), 0, this.employee.Id, DateTime.Now, this.txtRemarks.Text);
                    ACMSLogic.AuditTrail.AuditTrail audit = new ACMSLogic.AuditTrail.AuditTrail();
                    audit.SaveAuditTrail(trans, 8, "Save IBT " + this.nIBTNo, "IBT", this.employee.Id);

                    #region nHibernate Code
//					//DateTime
//					htIBT.Add("dtDate",DateTime.Now);
//					//int
//					//Status 0 - Pending Request
//					htIBT.Add("nStatusID",0);
//					//DateTime
//					htIBT.Add("dtLastEditDate",DateTime.Now);
//					//string
//					htIBT.Add("strRemarks",this.txtRemarks.Text);
//
//					//string
//					htIBT.Add("Branch_strBranchCodeFrom",this.terminalUser.Branch.Id);
//
//					//string
//					htIBT.Add("Branch_strBranchCodeTo",this.lkBranchTo.EditValue);
//
//					//int
//					htIBT.Add("Employee_nEmployeeID",this.employee.Id);
                    #endregion
                }
                ArrayList ibtEntryList = new ArrayList();

                ArrayList ibtProductTransferList = new ArrayList();

                DevExpress.XtraGrid.Columns.GridColumn col1 = gridView1.Columns.ColumnByFieldName("strItemCode");
                DevExpress.XtraGrid.Columns.GridColumn col2 = gridView1.Columns.ColumnByFieldName("nQuantity");
                DevExpress.XtraGrid.Columns.GridColumn col3 = gridView1.Columns.ColumnByFieldName("nEntryID");
                for (int i = 0; i < this.gridView1.DataRowCount; i++)
                {
                    object cellValue1 = gridView1.GetRowCellValue(i, col1);
                    object cellValue2 = gridView1.GetRowCellValue(i, col2);
                    object cellValue3 = null;

                    IBTProductTransfer ibt;
                    int nEntryID = 0;

                    string strProductCode = cellValue1.ToString();
                    int    quantity       = Convert.ToInt32(cellValue2.ToString());

                    if (isEdit)
                    {
                        cellValue3 = gridView1.GetRowCellValue(i, col3);
                        nEntryID   = Convert.ToInt32(cellValue3);
                        ibt        = new IBTProductTransfer(strProductCode, quantity, nEntryID);
                    }
                    else
                    {
                        ibt = new IBTProductTransfer(strProductCode, quantity);
                    }

                    if (ibtProductTransferList.Count == 0)
                    {
                        ibtProductTransferList.Add(ibt);
                    }
                    else
                    {
                        bool duplicate = false;
                        for (int _i = 0; _i < ibtProductTransferList.Count; _i++)
                        {
                            IBTProductTransfer _ibt = ibtProductTransferList[_i] as IBTProductTransfer;

                            if (strProductCode == _ibt.StrProductCode)
                            {
                                _ibt.Quantity = _ibt.Quantity + quantity;
                                duplicate     = true;
                            }
                        }

                        if (!duplicate)
                        {
                            ibtProductTransferList.Add(ibt);
                        }
                    }
                }

                //Variable Hashtable
                //bool doubleCheckCanSave=true;


                if (isEdit)
                {
                    foreach (IBTProductTransfer ibt in ibtProductTransferList)
                    {
                        if (!ibts.UpdateIBTEntries(trans, NIBTNo, ibt.StrProductCode, ibt.Quantity, this.terminalUser.Branch.Id, ibt.NEntryID))
                        {
                            trans.Rollback();
                            sqlcon.Close();
                            UI.ShowErrorMessage(this, "RollBack Transaction - Update IBTEntries", "Error");
                            return;
                        }
                    }
                    ACMSLogic.AuditTrail.AuditTrail audit = new ACMSLogic.AuditTrail.AuditTrail();
                    audit.SaveAuditTrail(trans, 8, "Update IBTEntries " + NIBTNo, "IBTEntries", this.employee.Id);

                    UI.ShowMessage(this, "Record Has Been Updated");
                }
                else
                {
                    if (nIBTNo != 0)
                    {
                        foreach (IBTProductTransfer ibt in ibtProductTransferList)
                        {
                            if (!ibts.SaveIBTEntries(trans, nIBTNo, ibt.StrProductCode, ibt.Quantity, this.terminalUser.Branch.Id))
                            {
                                trans.Rollback();
                                sqlcon.Close();
                                UI.ShowErrorMessage(this, "RollBack Transaction - Update StockRequestEntries", "Error");
                                return;
                            }
                            #region nHibernate Code
                            //					Hashtable htIBTEntries = new Hashtable();
                            //
                            //					htIBTEntries.Add("strItemCode",ibt.StrProductCode);
                            //					//int
                            //					htIBTEntries.Add("nQuantity",ibt.Quantity);
                            //
                            //					Rp.ProductRepository pr = new Rp.ProductRepository();
                            //
                            //					Acms.Core.Domain.ProductInventory pi = pr.CheckQuantityAvailable(ibt.StrProductCode,this.terminalUser.Branch.Id);
                            //					if(pi!=null)
                            //					{
                            //
                            //						if(!pi.IsValidQuantityRequest(ibt.Quantity))
                            //						{
                            //							doubleCheckCanSave=false;
                            //							//return;
                            //						}
                            //					}
                            //
                            //					ibtEntryList.Add(htIBTEntries);
                            #endregion
                        }
                        ACMSLogic.AuditTrail.AuditTrail audit = new ACMSLogic.AuditTrail.AuditTrail();
                        audit.SaveAuditTrail(trans, 8, "Save IBTEntries " + NIBTNo, "IBTEntries", this.employee.Id);
                    }
                    UI.ShowMessage(this, "Record Has Been Saved");
                }
            }

            trans.Commit();
            sqlcon.Close();
            this.DialogResult = DialogResult.OK;
        }