public t_trnsferNote Selectt_trnsferNote(t_trnsferNote objt_trnsferNote)
 {
     try
     {
         strquery = @"select * from t_trnsferNote where no = '" + objt_trnsferNote.no + "'";
         DataRow drType = u_DBConnection.ReturnDataRow(strquery);
         if (drType != null)
         {
             objt_trnsferNote.no               = drType["no"].ToString();
             objt_trnsferNote.sourceLocId      = drType["sourceLocId"].ToString();
             objt_trnsferNote.date             = DateTime.Parse(drType["date"].ToString());
             objt_trnsferNote.refNo            = drType["refNo"].ToString();
             objt_trnsferNote.remarks          = drType["remarks"].ToString();
             objt_trnsferNote.destinationLocId = drType["destinationLocId"].ToString();
             objt_trnsferNote.purchaseReqNo    = drType["purchaseReqNo"].ToString();
             objt_trnsferNote.noOfItems        = decimal.Parse(drType["noOfItems"].ToString());
             objt_trnsferNote.noOfPeaces       = decimal.Parse(drType["noOfPeaces"].ToString());
             objt_trnsferNote.grossAmount      = decimal.Parse(drType["grossAmount"].ToString());
             objt_trnsferNote.isSaved          = bool.Parse(drType["isSaved"].ToString());
             objt_trnsferNote.isProcessed      = bool.Parse(drType["isProcessed"].ToString());
             objt_trnsferNote.processDate      = DateTime.Parse(drType["processDate"].ToString());
             objt_trnsferNote.processUser      = drType["processUser"].ToString();
             objt_trnsferNote.GLUpdate         = bool.Parse(drType["GLUpdate"].ToString());
             objt_trnsferNote.triggerVal       = int.Parse(drType["triggerVal"].ToString());
             return(objt_trnsferNote);
         }
         return(null);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        /// <summary>
        /// Saves a record to the t_trnsferNote table.
        /// </summary>
        public Boolean Savet_trnsferNoteSP(t_trnsferNote t_trnsferNote, int formMode)
        {
            SqlCommand scom;
            bool       retvalue = false;

            try
            {
                scom             = new SqlCommand();
                scom.CommandType = CommandType.StoredProcedure;
                scom.CommandText = "T_trnsferNoteSave";

                scom.Parameters.Add("@no", SqlDbType.VarChar, 20).Value               = t_trnsferNote.no;
                scom.Parameters.Add("@sourceLocId", SqlDbType.VarChar, 20).Value      = t_trnsferNote.sourceLocId;
                scom.Parameters.Add("@date", SqlDbType.DateTime, 8).Value             = t_trnsferNote.date;
                scom.Parameters.Add("@refNo", SqlDbType.VarChar, 20).Value            = t_trnsferNote.refNo;
                scom.Parameters.Add("@remarks", SqlDbType.VarChar, 50).Value          = t_trnsferNote.remarks;
                scom.Parameters.Add("@destinationLocId", SqlDbType.VarChar, 20).Value = t_trnsferNote.destinationLocId;
                scom.Parameters.Add("@purchaseReqNo", SqlDbType.VarChar, 20).Value    = t_trnsferNote.purchaseReqNo;
                scom.Parameters.Add("@noOfItems", SqlDbType.Decimal, 9).Value         = t_trnsferNote.noOfItems;
                scom.Parameters.Add("@noOfPeaces", SqlDbType.Decimal, 9).Value        = t_trnsferNote.noOfPeaces;
                scom.Parameters.Add("@grossAmount", SqlDbType.Decimal, 9).Value       = t_trnsferNote.grossAmount;
                scom.Parameters.Add("@isSaved", SqlDbType.Bit, 1).Value               = t_trnsferNote.isSaved;
                scom.Parameters.Add("@isProcessed", SqlDbType.Bit, 1).Value           = t_trnsferNote.isProcessed;
                scom.Parameters.Add("@processDate", SqlDbType.DateTime, 8).Value      = t_trnsferNote.processDate;
                scom.Parameters.Add("@processUser", SqlDbType.VarChar, 20).Value      = t_trnsferNote.processUser;
                scom.Parameters.Add("@GLUpdate", SqlDbType.Bit, 1).Value              = t_trnsferNote.GLUpdate;
                scom.Parameters.Add("@triggerVal", SqlDbType.Int, 4).Value            = t_trnsferNote.triggerVal;
                scom.Parameters.Add("@InsMode", SqlDbType.Int).Value  = formMode; // For insert
                scom.Parameters.Add("@RtnValue", SqlDbType.Int).Value = 0;

                u_DBConnection dbcon = new u_DBConnection();
                retvalue = dbcon.RunQuery(scom);
                return(retvalue);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        public List <t_trnsferNote> SelectT_trnsferNoteMulti(t_trnsferNote objt_trnsferNote2)
        {
            List <t_trnsferNote> retval = new List <t_trnsferNote>();

            try
            {
                strquery = @"select * from t_trnsferNote where no = '" + objt_trnsferNote2.no + "'";
                DataTable dtt_trnsferNote = u_DBConnection.ReturnDataTable(strquery, CommandType.Text);
                foreach (DataRow drType in dtt_trnsferNote.Rows)
                {
                    if (drType != null)
                    {
                        t_trnsferNote objt_trnsferNote = new t_trnsferNote();
                        objt_trnsferNote.no               = drType["no"].ToString();
                        objt_trnsferNote.sourceLocId      = drType["sourceLocId"].ToString();
                        objt_trnsferNote.date             = DateTime.Parse(drType["date"].ToString());
                        objt_trnsferNote.refNo            = drType["refNo"].ToString();
                        objt_trnsferNote.remarks          = drType["remarks"].ToString();
                        objt_trnsferNote.destinationLocId = drType["destinationLocId"].ToString();
                        objt_trnsferNote.purchaseReqNo    = drType["purchaseReqNo"].ToString();
                        objt_trnsferNote.noOfItems        = decimal.Parse(drType["noOfItems"].ToString());
                        objt_trnsferNote.noOfPeaces       = decimal.Parse(drType["noOfPeaces"].ToString());
                        objt_trnsferNote.grossAmount      = decimal.Parse(drType["grossAmount"].ToString());
                        objt_trnsferNote.isSaved          = bool.Parse(drType["isSaved"].ToString());
                        objt_trnsferNote.isProcessed      = bool.Parse(drType["isProcessed"].ToString());
                        objt_trnsferNote.processDate      = DateTime.Parse(drType["processDate"].ToString());
                        objt_trnsferNote.processUser      = drType["processUser"].ToString();
                        objt_trnsferNote.GLUpdate         = bool.Parse(drType["GLUpdate"].ToString());
                        objt_trnsferNote.triggerVal       = int.Parse(drType["triggerVal"].ToString());
                        retval.Add(objt_trnsferNote);
                    }
                }
                return(retval);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void FindExisitingTransfer(string ReqNo)
        {
            try
            {
                if (T_trnsferNoteDL.ExistingT_trnsferNote(ReqNo.Trim()))
                {
                    formMode = 3;
                    //clear datagrid
                    dtx.Clear();
                    dataGridView1.Refresh();

                    //clear error fields
                    errorProvider1.Clear();

                    t_trnsferNote cat = new t_trnsferNote();
                    cat.no = ReqNo.Trim();
                    T_trnsferNoteDL dl = new T_trnsferNoteDL();
                    cat = dl.Selectt_trnsferNote(cat);

                    //set the process message and mode to edit mode
                    if (cat.isProcessed == false)
                    {
                        lbl_processes.Visible = false;
                        performButtons(xEnums.PerformanceType.Edit);
                    }
                    else
                    {
                        lbl_processes.Visible = true;
                    }

                    //load and disable the data fields

                    txt_destinationLocId.Text = cat.destinationLocId.Trim();
                    txt_sourceLocId.Text      = cat.sourceLocId.Trim();
                    //txt_supplierId.Text = cat.supplierId.Trim();
                    txt_remarks.Text = cat.remarks;
                    dte_date.Value   = cat.date;

                    textareaFunctions(false);

                    t_transfer_detail req = new t_transfer_detail();
                    req.transferNoteNo = ReqNo.Trim();
                    T_transfer_detailDL      tdl      = new T_transfer_detailDL();
                    List <t_transfer_detail> requests = new List <t_transfer_detail>();
                    requests = tdl.SelectT_transfer_detailMulti(req);

                    foreach (t_transfer_detail det in requests)
                    {
                        commonFunctions.AddRow(dtx, det.stockCode, findExisting.FindExisitingStock(det.stockCode).Trim(), det.costPrice.ToString(), det.costPrice.ToString(), det.quantity.ToString(), det.amount.ToString());
                    }

                    txt_net.Text         = commonFunctions.GetGrossAmount(dataGridView1).ToString();
                    txt_grossAmount.Text = commonFunctions.GetGrossAmount(dataGridView1).ToString();
                    txt_noOfPeaces.Text  = commonFunctions.GetNoofPices(dataGridView1).ToString();
                    txt_noOfItems.Text   = commonFunctions.GetNoofItems(dataGridView1).ToString();
                }
                else
                {
                    if (formMode != 1)
                    {
                        errorProvider1.SetError(txt_no, "Request Number you have entered does not exists in the system.");
                    }
                }
            }
            catch (Exception ex)
            {
                LogFile.WriteErrorLog(System.Reflection.MethodBase.GetCurrentMethod().Name, this.Name, ex.Message.ToString(), "Exception");
                commonFunctions.SetMDIStatusMessage("Genaral Error", 1);
            }
        }
        private void performButtons(xEnums.PerformanceType xenum)
        {
            try
            {
                switch (xenum)
                {
                case xEnums.PerformanceType.View:
                    if (ActiveControl.Name.Trim() == txt_no.Name.Trim())
                    {
                        int      length         = Convert.ToInt32(ConfigurationManager.AppSettings["POFieldLength"]);
                        string[] strSearchField = new string[length];

                        string strSQL = ConfigurationManager.AppSettings["POSQL"].ToString();

                        for (int i = 0; i < length; i++)
                        {
                            string m;
                            m = i.ToString();
                            strSearchField[i] = ConfigurationManager.AppSettings["POField" + m + ""].ToString();
                        }

                        frmU_Search find = new frmU_Search(strSQL, strSearchField, this);
                        find.ShowDialog(this);
                    }

                    break;

                case xEnums.PerformanceType.New:
                    FunctionButtonStatus(xEnums.PerformanceType.New);
                    formMode    = 1;
                    txt_no.Text = commonFunctions.GetSerial(formID.Trim());
                    txt_no.Focus();

                    txt_sourceLocId.Text     = commonFunctions.GlobalLocation;
                    txt_locationId_name.Text = findExisting.FindExisitingLoca(txt_sourceLocId.Text.Trim());

                    errorProvider1.Clear();

                    lbl_processes.Visible = false;
                    break;

                case xEnums.PerformanceType.Edit:
                    FunctionButtonStatus(xEnums.PerformanceType.Edit);
                    formMode = 3;
                    //txt_VehicleID.Enabled = false;
                    //txt_VehicleNo.Focus();
                    errorProvider1.Clear();
                    break;

                case xEnums.PerformanceType.Save:
                    errorProvider1.Clear();
                    if (formMode == 1)
                    {
                        if (!M_LocaDL.ExistingM_Loca(txt_sourceLocId.Text.Trim()))
                        {
                            errorProvider1.SetError(txt_sourceLocId, "Location does not exists on the system ");
                            commonFunctions.SetMDIStatusMessage("Location does not exists on the system", 1);
                            return;
                        }

                        if (txt_sourceLocId.Text.Trim().ToUpper() == txt_destinationLocId.Text.Trim().ToUpper())
                        {
                            errorProvider1.SetError(txt_destinationLocId, "Destination location cannot same as login location");
                            return;
                        }

                        if (commonFunctions.GetNoofItems(dataGridView1) <= 0)
                        {
                            errorProvider1.SetError(dataGridView1, "Please enter some items to the details grid");
                            commonFunctions.SetMDIStatusMessage("Please enter some items to the details grid", 1);
                            return;
                        }



                        if (UserDefineMessages.ShowMsg("", UserDefineMessages.Msg_PerfmBtn_Save, commonFunctions.Softwarename.Trim()) == System.Windows.Forms.DialogResult.Yes)
                        {
                            try
                            {
                                using (System.Transactions.TransactionScope transaction = new System.Transactions.TransactionScope())
                                {
                                    //u_DBConnection.BeginTrans();
                                    //save header data
                                    t_trnsferNote objt_trnsferNote = new t_trnsferNote();
                                    objt_trnsferNote.no               = txt_no.Text.Trim();
                                    objt_trnsferNote.sourceLocId      = commonFunctions.GlobalLocation;
                                    objt_trnsferNote.date             = dte_date.Value;
                                    objt_trnsferNote.refNo            = txt_refNo.Text.Trim();
                                    objt_trnsferNote.remarks          = txt_remarks.Text.Trim();
                                    objt_trnsferNote.destinationLocId = txt_destinationLocId.Text.Trim();
                                    objt_trnsferNote.purchaseReqNo    = txt_purchaseReqNo.Text.Trim();
                                    objt_trnsferNote.noOfItems        = commonFunctions.ToDecimal(txt_noOfItems.Text.Trim());
                                    objt_trnsferNote.noOfPeaces       = commonFunctions.ToDecimal(txt_noOfPeaces.Text.Trim());
                                    objt_trnsferNote.grossAmount      = commonFunctions.ToDecimal(txt_grossAmount.Text.Trim());
                                    objt_trnsferNote.isSaved          = true;
                                    objt_trnsferNote.isProcessed      = false;
                                    objt_trnsferNote.processDate      = DateTime.Now;
                                    objt_trnsferNote.processUser      = "";
                                    objt_trnsferNote.GLUpdate         = false;
                                    objt_trnsferNote.triggerVal       = 1;
                                    T_trnsferNoteDL bal = new T_trnsferNoteDL();
                                    bal.Savet_trnsferNoteSP(objt_trnsferNote, 1);



                                    //save details
                                    foreach (DataGridViewRow drow in dataGridView1.Rows)
                                    {
                                        if (drow.Cells["Product Code"].Value.ToString().Trim() != null)
                                        {
                                            t_transfer_detail objt_transfer_detail = new t_transfer_detail();
                                            objt_transfer_detail.transferNoteNo = txt_no.Text.Trim();
                                            objt_transfer_detail.sourceLocId    = commonFunctions.GlobalLocation;
                                            objt_transfer_detail.transferDate   = dte_date.Value;
                                            objt_transfer_detail.stockCode      = drow.Cells["Product Code"].Value.ToString();
                                            objt_transfer_detail.description    = drow.Cells["Product Name"].Value.ToString();
                                            objt_transfer_detail.quantity       = commonFunctions.ToDecimal(drow.Cells["Quntity"].Value.ToString());
                                            objt_transfer_detail.costPrice      = commonFunctions.ToDecimal(drow.Cells["Cost Price"].Value.ToString());
                                            objt_transfer_detail.amount         = commonFunctions.ToDecimal(drow.Cells["Amount"].Value.ToString());
                                            objt_transfer_detail.triggerVal     = 1;
                                            T_transfer_detailDL baldet = new T_transfer_detailDL();
                                            baldet.Savet_transfer_detailSP(objt_transfer_detail, 1);
                                        }
                                    }
                                    //increment the serial
                                    commonFunctions.IncrementSerial(formID);
                                    //u_DBConnection.CommitTrans();
                                    UserDefineMessages.ShowMsg("", UserDefineMessages.Msg_Save_Sucess, commonFunctions.Softwarename.Trim());
                                    transaction.Complete();
                                }
                            }
                            catch (Exception ex)
                            {
                                // u_DBConnection.RollbackTrans();
                                LogFile.WriteErrorLog("Save Transactions", "Transfer Out", ex.Message);
                                commonFunctions.SetMDIStatusMessage("Transfer Number you have entered already processed", 1);
                            }

                            if (UserDefineMessages.ShowMsg("", UserDefineMessages.Msg_PerfmBtn_Process, commonFunctions.Softwarename.Trim()) == System.Windows.Forms.DialogResult.Yes)
                            {
                                UpdateStock();

                                t_trnsferNote objt_trnsferNote = new t_trnsferNote();
                                objt_trnsferNote.no = txt_no.Text.Trim();

                                T_trnsferNoteDL balprocess = new T_trnsferNoteDL();
                                objt_trnsferNote = balprocess.Selectt_trnsferNote(objt_trnsferNote);

                                objt_trnsferNote.isProcessed = true;
                                objt_trnsferNote.processDate = DateTime.Now;
                                objt_trnsferNote.processUser = commonFunctions.Loginuser;
                                balprocess.Savet_trnsferNoteSP(objt_trnsferNote, 3);

                                UserDefineMessages.ShowMsg("", UserDefineMessages.Msg_Update_Sucess, commonFunctions.Softwarename.Trim());
                            }


                            //clear data in data grid
                            dtx.Rows.Clear();
                            dataGridView1.Refresh();
                            //clear text fields
                            textareaFunctions(true);

                            FunctionButtonStatus(xEnums.PerformanceType.Save);
                            //increment the serial
                            txt_no.Text = commonFunctions.GetSerial(formID.Trim());
                            //txt_supplierId.Focus();
                        }
                    }
                    else if (formMode == 3)
                    {
                        t_trnsferNote cat = new t_trnsferNote();
                        cat.no = txt_no.Text.Trim();
                        T_trnsferNoteDL dl = new T_trnsferNoteDL();
                        cat = dl.Selectt_trnsferNote(cat);
                        if (cat.isProcessed == false)
                        {
                            if (UserDefineMessages.ShowMsg("", UserDefineMessages.Msg_PerfmBtn_Process, commonFunctions.Softwarename.Trim()) == System.Windows.Forms.DialogResult.Yes)
                            {
                                UpdateStock();

                                t_trnsferNote objt_trnsferNote = new t_trnsferNote();
                                objt_trnsferNote.no = txt_no.Text.Trim();

                                T_trnsferNoteDL balprocess = new T_trnsferNoteDL();
                                objt_trnsferNote = balprocess.Selectt_trnsferNote(objt_trnsferNote);

                                objt_trnsferNote.isProcessed = true;
                                objt_trnsferNote.processDate = DateTime.Now;
                                objt_trnsferNote.processUser = commonFunctions.Loginuser;
                                balprocess.Savet_trnsferNoteSP(objt_trnsferNote, 3);
                                UserDefineMessages.ShowMsg("", UserDefineMessages.Msg_Update_Sucess, commonFunctions.Softwarename.Trim());

                                //clear data in data grid
                                dtx.Rows.Clear();
                                dataGridView1.Refresh();
                                //clear text fields
                                textareaFunctions(true);
                                FunctionButtonStatus(xEnums.PerformanceType.Save);

                                txt_no.Text = commonFunctions.GetSerial(formID.Trim());
                                txt_refNo.Focus();
                            }
                        }
                        else
                        {
                            errorProvider1.SetError(txt_no, "Transfer Number you have entered already processed.");
                            commonFunctions.SetMDIStatusMessage("Transfer Number you have entered already processed", 1);
                        }
                    }
                    break;

                case xEnums.PerformanceType.Cancel:
                    txt_no.Enabled = true;
                    FunctionButtonStatus(xEnums.PerformanceType.Default);
                    errorProvider1.Clear();
                    //clear text fields
                    textareaFunctions(true);
                    //clear Datagrid
                    dtx.Clear();
                    dataGridView1.Refresh();

                    //txt_supplierId.Text = "";
                    txt_remarks.Text = "";

                    lbl_processes.Visible = false;

                    break;

                case xEnums.PerformanceType.Print:
                    UserDefineMessages.ShowMsg1("Print still in process", UserDefineMessages.Msg_Information);
                    break;
                }
            }
            catch (Exception ex)
            {
                LogFile.WriteErrorLog(System.Reflection.MethodBase.GetCurrentMethod().Name, this.Name, ex.Message.ToString(), "Exception");
                commonFunctions.SetMDIStatusMessage("Genaral Error on updating data", 1);
            }
        }