private void btnUpdate_Click(object sender, EventArgs e) { if (MessageBox.Show("Do you want to Update current record ?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) ; { int InvoiceStatus = MyInvoice.GetInvoiceStatus(cmbGRN .Text); switch (InvoiceStatus) { case 0: InvoiceDataTypes.InvoiceDataType _saveData = new InvoiceDataTypes.InvoiceDataType(); if (MyInvoice.ExistInvoice(_saveData.InvoiceNo)) { string respond = SetDatatoClass(out _saveData); if (respond == "True") { respond = MyInvoice.Update(_saveData); if (respond == "True") Program.InformationMessage("Saved Successfully"); else Program.VerningMessage(respond); } else Program.VerningMessage(respond); } else Program.VerningMessage("Use Save Button"); break; case 2: Program.VerningMessage("Already Approved Invoice cannot change"); break; case 3: Program.VerningMessage("Already Accounted Invoice cannot change"); break; default: break; } } }
public string GetExistInvoice(string InvoiceNo, out InvoiceDataTypes.InvoiceDataType _ExistData) { _ExistData = new InvoiceDataTypes.InvoiceDataType(); MySqlCommand oSqlCommand = new MySqlCommand(); string sqlQuery = "Select " + "InvoiceNo," + "Description," + "AccountID," + "CurRate," + "Dr," + "FDr," + "InvoiceStatus," + "TrRef," + "TrUser," + "TrDate," + "TrTime," + "AccPeriod," + "CompanyID," + "RcvFromCatID," + "RcvFromID," + "RcvAmount," + "TobeRcvDate," + "InvoiceDate," + "ApproveBy," + "ApproveDate," + "ApproveTime," + "AcountedBy," + "AccountDate," + "AccountedTime" + " from tblrecievebleinvoice" + " Where 1=1 " + " and InvoiceNo=@InvoiceNo"; oSqlCommand.Parameters.AddWithValue("@InvoiceNo", InvoiceNo); DataRow r = Mycommon.GetDataRowAccount(sqlQuery, oSqlCommand, "Get Exist data Invoice"); if (r != null) { try { bool resp = false; _ExistData.InvoiceNo = r["InvoiceNo"].ToString(); _ExistData.Description = r["Description"].ToString(); _ExistData.AccountID = r["AccountID"].ToString(); decimal deCurRate = 0; resp = decimal.TryParse(r["CurRate"].ToString(), out deCurRate); _ExistData.CurRate = deCurRate; decimal deDr = 0; resp = decimal.TryParse(r["Dr"].ToString(), out deDr); _ExistData.Dr = deDr; decimal deFDr = 0; resp = decimal.TryParse(r["FDr"].ToString(), out deFDr); _ExistData.FDr = deFDr; int inInvoiceStatus = 0; resp = int.TryParse(r["InvoiceStatus"].ToString(), out inInvoiceStatus); _ExistData.InvoiceStatus = inInvoiceStatus; _ExistData.TrRef = r["TrRef"].ToString(); _ExistData.TrUser = r["TrUser"].ToString(); DateTime dtTrDate = new DateTime(1900, 1, 1); resp = DateTime.TryParse(r["TrDate"].ToString(), out dtTrDate); if (resp) _ExistData.TrDate = dtTrDate; else _ExistData.TrDate = new DateTime(1900, 1, 1); _ExistData.TrTime = r["TrTime"].ToString(); int inAccPeriod = 0; resp = int.TryParse(r["AccPeriod"].ToString(), out inAccPeriod); _ExistData.AccPeriod = inAccPeriod; int inCompanyID = 0; resp = int.TryParse(r["CompanyID"].ToString(), out inCompanyID); _ExistData.CompanyID = inCompanyID; int inRcvFromCatID = 0; resp = int.TryParse(r["RcvFromCatID"].ToString(), out inRcvFromCatID); _ExistData.RcvFromCatID = inRcvFromCatID; int inRcvFromID = 0; resp = int.TryParse(r["RcvFromID"].ToString(), out inRcvFromID); _ExistData.RcvFromID = inRcvFromID; decimal deRcvAmount = 0; resp = decimal.TryParse(r["RcvAmount"].ToString(), out deRcvAmount); _ExistData.RcvAmount = deRcvAmount; DateTime dtTobeRcvDate = new DateTime(1900, 1, 1); resp = DateTime.TryParse(r["TobeRcvDate"].ToString(), out dtTobeRcvDate); if (resp) _ExistData.TobeRcvDate = dtTobeRcvDate; else _ExistData.TobeRcvDate = new DateTime(1900, 1, 1); DateTime dtInvoiceDate = new DateTime(1900, 1, 1); resp = DateTime.TryParse(r["InvoiceDate"].ToString(), out dtInvoiceDate); if (resp) _ExistData.InvoiceDate = dtInvoiceDate; else _ExistData.InvoiceDate = new DateTime(1900, 1, 1); _ExistData.ApproveBy = r["ApproveBy"].ToString(); DateTime dtApproveDate = new DateTime(1900, 1, 1); resp = DateTime.TryParse(r["ApproveDate"].ToString(), out dtApproveDate); if (resp) _ExistData.ApproveDate = dtApproveDate; else _ExistData.ApproveDate = new DateTime(1900, 1, 1); _ExistData.ApproveTime = r["ApproveTime"].ToString(); _ExistData.AcountedBy = r["AcountedBy"].ToString(); DateTime dtAccountDate = new DateTime(1900, 1, 1); resp = DateTime.TryParse(r["AccountDate"].ToString(), out dtAccountDate); if (resp) _ExistData.AccountDate = dtAccountDate; else _ExistData.AccountDate = new DateTime(1900, 1, 1); _ExistData.AccountedTime = r["AccountedTime"].ToString(); List<InvoiceDataTypes.InvoiceDetailsDataType> _ExistDataList = new List<InvoiceDataTypes.InvoiceDetailsDataType>(); string respond = GetInvoiceDetailList(InvoiceNo, out _ExistDataList); _ExistData.InvoiceDtails = _ExistDataList; return "True"; } catch (Exception ex) { return ex.Message; } } else return "data not found "; }
private string SetDatatoClass(out InvoiceDataTypes.InvoiceDataType _saveData) { _saveData = new InvoiceDataTypes.InvoiceDataType(); try { decimal TotalLKR = 0, TotalUSD = 0; bool resp = decimal.TryParse(lblTotalAmount.Text, out TotalLKR); resp = decimal.TryParse(lblFcr.Text, out TotalUSD); string supid = MyCommon.GetSelectedID(cmbSupplier, true); int SupID1 = int.Parse(supid); _saveData.AccPeriod = Program.AccountStatic.CurrentAccPeriod; _saveData.AccountID = lblAccnumber.Text; _saveData.CompanyID = Program.AccountStatic.CompanyID; _saveData.CurRate = decimal.Parse(lblExchangerate.Text); _saveData.Description = txtDescription.Text; _saveData.Dr = TotalLKR; _saveData.FDr = TotalUSD; _saveData.InvoiceDate = dtpInvoiceDate.Value; _saveData.InvoiceNo = cmbGRN.Text; _saveData.InvoiceStatus = 0; _saveData.RcvAmount = TotalLKR; _saveData.RcvFromCatID = 0; _saveData.RcvFromID = SupID1; _saveData.TobeRcvDate = DateTime.Parse(lblDueDate.Text); _saveData.TrUser = Program.AccountStatic.UserName; List<InvoiceDataTypes.InvoiceDetailsDataType> _DetailList = new List<InvoiceDataTypes.InvoiceDetailsDataType>(); string respond = SetDetailsToClass(out _DetailList); _saveData.InvoiceDtails = _DetailList; return "True"; } catch (Exception ex) { return ex.Message; } }