private void dgvAppParameter_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { string briefMsg, detailMsg; if (!UserService.AllowToPerform(Resources.PermissionDeleteConfig)) { briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } //ExtendedMessageBox.InformMessage(Resources.MsgUserPermissionDeny); //return; } var appParameter = (AppParameter)_AppParamList[e.Row.Index]; briefMsg = "អំពីការលុប"; detailMsg = Resources.MsgOperationRequestDelete + "\n" + appParameter.ParameterLabel + " ?"; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; if (frmMessageBox.ShowDialog(this) != DialogResult.OK) { e.Cancel = true; return; } } //if (!ExtendedMessageBox.ConfirmMessage(Resources.MsgOperationRequestDelete, appParameter.ParameterLabel)) //{ // e.Cancel = true; // return; //} AppParamManagement(appParameter, Resources.OperationRequestDelete); _AppParamList = _CommonService .GetAppParametersByType(Int32.Parse(lsbAppParam.SelectedValue.ToString(), AppContext.CultureInfo)); cmbAppParamValue.DataSource = _AppParamList; if (StringHelper.Length(cmbAppParamValue.DisplayMember) == 0) { cmbAppParamValue.DisplayMember = AppParameter.ConstParameterValue; } if (StringHelper.Length(cmbAppParamValue.ValueMember) == 0) { cmbAppParamValue.ValueMember = AppParameter.ConstParameterId; } cmbAppParamValue.SelectedIndex = _AppParamList.Count - 1; }
private void BtnDelete_Click(object sender, EventArgs e) { string briefMsg, detailMsg; if (!UserService.AllowToPerform(Resources.PermissionDeleteCard)) { briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } //ExtendedMessageBox.InformMessage(Resources.MsgUserPermissionDeny); //return; } //if (!ExtendedMessageBox.ConfirmMessage( // "MsgOperationRequestDelete", // "\n\n" + dgvDiscountCard.CurrentRow.Cells["CardNumber"].Value)) // return; //string briefMsg, detailMsg; briefMsg = "អំពីការលុប"; detailMsg = Resources.MsgOperationRequestDelete + "\n" + dgvDiscountCard.CurrentRow.Cells["CardNumber"].Value + " ?"; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; if (frmMessageBox.ShowDialog(this) != DialogResult.OK) { return; } } try { _CustomerService.DiscountCardManagement( (DiscountCard)_DiscountCardList[dgvDiscountCard.CurrentRow.Index], Resources.OperationRequestDelete); _DiscountCardList.RemoveAt(dgvDiscountCard.CurrentRow.Index); dgvDiscountCard.Refresh(); UpdateResultInfo(); EnableActionButton(); } catch (Exception exception) { FrmExtendedMessageBox.UnknownErrorMessage( Resources.MsgCaptionUnknownError, exception.Message); } }
private void BtnDeleteClick(object sender, EventArgs e) { string briefMsg, detailMsg; if (!UserService.AllowToPerform(Resources.PermissionDeleteCustomer)) { briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } SetFocusToCustomerList(); //string briefMsg, detailMsg; briefMsg = "អំពីការលុប"; detailMsg = Resources.MsgOperationRequestDelete + "\n" + dgvCustomer.CurrentRow.Cells["CustomerName"].Value + " ?"; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; if (frmMessageBox.ShowDialog(this) != DialogResult.OK) { return; } } try { _customerService.CustomerManagement( _customerList[dgvCustomer.CurrentRow.Index], Resources.OperationRequestDelete); ThreadStart threadStart = UpdateControlContent; var thread = new Thread(threadStart); thread.Start(); _customerList.RemoveAt(dgvCustomer.CurrentRow.Index); dgvCustomer.Refresh(); UpdateResultInfo(); EnableActionButton(); } catch (Exception exception) { FrmExtendedMessageBox.UnknownErrorMessage( Resources.MsgCaptionUnknownError, exception.Message); } }
private void btnReturnCard_Click(object sender, EventArgs e) { var discountCard = (DiscountCard)_DiscountCardList[dgvDiscountCard.CurrentRow.Index]; if (discountCard.CustomerId == 0) { return; } string briefMsg, detailMsg; if (!UserService.AllowToPerform(Resources.PermissionGetBackCard)) { briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } briefMsg = "អំពីការដកហូតប័ណ្ណបញ្ចុះតំលៃ"; detailMsg = Resources.MsgOperationRequestGetBackCard + discountCard.CustomerStr + " ។"; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; if (frmMessageBox.ShowDialog(this) != DialogResult.OK) { return; } } try { discountCard.CustomerId = 0; discountCard.CustomerStr = ""; _CustomerService.DiscountCardManagement( discountCard, Resources.OperationRequestUpdate); btnReturnCard.Enabled = false; } catch (Exception exception) { FrmExtendedMessageBox.UnknownErrorMessage( Resources.MsgCaptionUnknownError, exception.Message); } }
private void RefreshReportDeposit(bool allDeposit) { if (!UserService.AllowToPerform(Resources.PermissionViewDepositReport)) { const string briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; var detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } var searchCriteria = !allDeposit ? new List <string> { "(DepositDate BETWEEN CONVERT(DATETIME, '" + dtpStartDate.Value.ToString("dd/MM/yyyy", AppContext.CultureInfo) + "', 103) AND CONVERT(DATETIME, '" + dtpStopDate.Value.ToString("dd/MM/yyyy", AppContext.CultureInfo) + " 23:59', 103)) ", "(AmountPaidInt < AmountSoldInt) ", "DepositNumber NOT IN (SELECT ReferenceNum FROM TDeposits WHERE ReferenceNum IS NOT NULL) " } : new List <string> { "(DepositDate BETWEEN CONVERT(DATETIME, '" + dtpStartDate.Value.ToString("dd/MM/yyyy", AppContext.CultureInfo) + "', 103) AND CONVERT(DATETIME, '" + dtpStopDate.Value.ToString("dd/MM/yyyy", AppContext.CultureInfo) + " 23:59', 103)) " }; var assessmentList = _depositService.GetDepositHistories(searchCriteria, false); DataSet dtsModel = new DtsModels(); var propertyInfos = typeof(DepositReport).GetProperties(); foreach (var objInstance in assessmentList) { var dataRow = dtsModel.Tables[3].NewRow(); foreach (var propertyInfo in propertyInfos) { dataRow[propertyInfo.Name] = propertyInfo.GetValue(objInstance, null); } dtsModel.Tables[3].Rows.Add(dataRow); } var rptDeposit = new CsrDeposit(); rptDeposit.SetDataSource(dtsModel); crvReport.ReportSource = rptDeposit; }
private void BtnSearchSaleClick(object sender, EventArgs e) { try { if (!UserService.AllowToPerform(Resources.PermissionByDatesReport)) { if ((!dtpStartDate.Value.Date.Equals(DateTime.Today)) || (!dtpStopDate.Value.Date.Equals(DateTime.Today))) { const string briefMsg = "សិទ្ធមើល របាយការណ៏តាមថ្ងៃ"; var detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } } crvReport.BringToFront(); if (rdbSale.Checked) { RefreshReportSale(); } else if (rdbDeposit.Checked) { RefreshReportDeposit(chbAllDeposit.Checked); } else if (rdbReturn.Checked) { RefreshReportReturn(); } else if (rdbExpense.Checked) { RefreshDailyExpenseReport(); } else { RefreshIncomeStatementReport(); } } catch (Exception exception) { FrmExtendedMessageBox.UnknownErrorMessage( Resources.MsgCaptionUnknownError, exception.Message); throw; } }
private void BtnDeleteClick(object sender, EventArgs e) { string briefMsg, detailMsg; if (!UserService.AllowToPerform(Resources.PermissionDeleteExpense)) { briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } briefMsg = "អំពីការលុប"; detailMsg = Resources.MsgOperationRequestDelete + "\n" + dgvExpense.CurrentRow.Cells["Description"].Value + " ?"; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; if (frmMessageBox.ShowDialog(this) != DialogResult.OK) { return; } } try { _ExpenseService.ExpenseManagement(_ExpenseList[dgvExpense.CurrentRow.Index], Resources.OperationRequestDelete); _ExpenseList.RemoveAt(dgvExpense.CurrentRow.Index); dgvExpense.Refresh(); UpdateResultInfo(); EnableActionButton(); } catch (Exception exception) { FrmExtendedMessageBox.UnknownErrorMessage( Resources.MsgCaptionUnknownError, exception.Message); } }
private void RefreshReportReturn() { if (!UserService.AllowToPerform(Resources.PermissionViewReturnProductReport)) { const string briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; var detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } var searchCriteria = new List <string> { "SaleOrderNumber IN (SELECT SaleOrderNumber FROM TSaleOrders WHERE SaleOrderTypeId = 1)", "SaleOrderDate BETWEEN CONVERT(DATETIME, '" + dtpStartDate.Value.ToString("dd/MM/yyyy", AppContext.CultureInfo) + "', 103) AND CONVERT(DATETIME, '" + dtpStopDate.Value.ToString("dd/MM/yyyy", AppContext.CultureInfo) + " 23:59', 103)" }; var assessmentList = _SaleOrderService.GetSaleHistories(searchCriteria); DataSet dtsModel = new DtsModels(); var propertyInfos = typeof(SaleOrderReport).GetProperties(); foreach (var objInstance in assessmentList) { var dataRow = dtsModel.Tables[1].NewRow(); foreach (var propertyInfo in propertyInfos) { dataRow[propertyInfo.Name] = propertyInfo.GetValue(objInstance, null); } dtsModel.Tables[1].Rows.Add(dataRow); } var rptSaleReturn = new CsrSaleReturn(); rptSaleReturn.SetDataSource(dtsModel); crvReport.ReportSource = rptSaleReturn; }
private void BtnNewProductClick(object sender, EventArgs e) { if (!UserService.AllowToPerform(Resources.PermissionAddProduct)) { const string briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; var detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } ProductManagement(Resources.OperationRequestInsert); }
private void dgvExpense_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (!UserService.AllowToPerform(Resources.PermissionEditExpense)) { const string briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; var detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } ExpenseManagement(Resources.OperationRequestUpdate); }
private void RefreshDailyExpenseReport() { if (!UserService.AllowToPerform(Resources.PermissionViewExpenseReport)) { const string briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; var detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } var searchCriteria = new List <string> { "CONVERT(DATETIME, ExpenseDate, 103) BETWEEN CONVERT(DATETIME, '" + dtpStartDate.Value.ToString("dd/MM/yyyy", AppContext.CultureInfo) + "', 103) AND CONVERT(DATETIME, '" + dtpStopDate.Value.ToString("dd/MM/yyyy", AppContext.CultureInfo) + " 23:59', 103)" }; var expenseList = _ExpenseService.GetExpenses(searchCriteria); DataSet dtsProduct = new DtsModels(); var propertyInfos = typeof(Expense).GetProperties(); foreach (var objInstance in expenseList) { var dataRow = dtsProduct.Tables["DtbExpenses"].NewRow(); foreach (var propertyInfo in propertyInfos) { dataRow[propertyInfo.Name] = propertyInfo.GetValue(objInstance, null); } dtsProduct.Tables["DtbExpenses"].Rows.Add(dataRow); } var csrExpense = new CsrExpense(); csrExpense.SetDataSource(dtsProduct); crvReport.ReportSource = csrExpense; }
private void DoPrintProduct() { try { if (!UserService.AllowToPerform(Resources.PermissionPrintProductCode)) { const string briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; var detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } //Generate product to print var selectedProductList = new BindingList <Product>(); foreach (var product in _productList.Where(product => product != null).Where(product => product.PrintCheck)) { selectedProductList.Add(product); } PrintProduct.InializePrinting(selectedProductList); SetFocusToProductList(); } catch (Exception exception) { FrmExtendedMessageBox.UnknownErrorMessage( Resources.MsgCaptionUnknownError, exception.Message); } }
private void btnNew_Click(object sender, EventArgs e) { if (cmbDiscountType.SelectedValue == null) { return; } if (txtNumCard.Text.Length == 0) { return; } try { if (!UserService.AllowToPerform(Resources.PermissionAddCard)) { const string briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; var detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } var discountCardTypeId = Int32.Parse(cmbDiscountType.SelectedValue.ToString(), AppContext.CultureInfo); var discountCardTypeStr = ((AppParameter)cmbDiscountType.SelectedItem).ParameterLabel; var discountPercentage = float.Parse(((AppParameter)cmbDiscountType.SelectedItem).ParameterValue, AppContext.CultureInfo); var nbrDiscountCard = Int32.Parse(txtNumCard.Text, AppContext.CultureInfo); for (var counter = 0; counter < nbrDiscountCard; counter++) { var discountCard = new DiscountCard { DiscountCardTypeId = discountCardTypeId, DiscountCardTypeStr = discountCardTypeStr, DiscountPercentage = discountPercentage, ExpireDate = DateTime.Now, AllowDiscount = 1 }; _CustomerService.DiscountCardManagement( discountCard, Resources.OperationRequestInsert); _DiscountCardList.Add(discountCard); } dgvDiscountCard.Refresh(); SetDiscountCardInfo(); UpdateResultInfo(); EnableActionButton(); } catch (Exception exception) { FrmExtendedMessageBox.UnknownErrorMessage( Resources.MsgCaptionUnknownError, exception.Message); } }
private void BtnPrintClick(object sender, EventArgs e) { try { if (!UserService.AllowToPerform(Resources.PermissionPrintProductCode)) { const string briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; var detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } if (rdbProduct.Checked) { DoPrintProduct(); return; } if (rdbPrintAll.Checked) { _barCodeList.Clear(); foreach (var t in _productList) { var product = t; if (product == null) { continue; } for (var qtyCounter = 0; qtyCounter < product.QtyInStock; qtyCounter++) { //var product = _ProductList[counter]; var barCode = new BarCode { BarCodeValue = product.ProductCode, DisplayStr = product.CategoryStr, AdditionalStr = (product.QtyInStock.ToString("N0") + " / " + product.QtyInStock.ToString("N0")), UnitPrice = "$ " + (t).UnitPriceOut.ToString("N", AppContext.CultureInfo), Description = product.ProductName + @" \ " + product.SizeStr }; var foreignCode = product.ForeignCode; if (!string.IsNullOrEmpty(foreignCode)) { barCode.DisplayStr += " (" + foreignCode + ")"; } _barCodeList.Add(barCode); } (t).PrintCheck = true; (t).PublicQty = (t).QtyInStock + " / " + (t).QtyInStock; } dgvProduct.Refresh(); } var barCodeTemplate = AppContext.BarCodeTemplate; //var barCodePrintingTypeList = // _CommonService.GetAppParametersByType( // Int32.Parse(Resources.AppParamBarcodePrintingType, AppContext.CultureInfo)); //var barCodePrintingType = string.Empty; //if (barCodePrintingTypeList != null) //{ // if(barCodePrintingTypeList.Count != 0) // { // var appParameter = (AppParameter) barCodePrintingTypeList[0]; // if (appParameter != null) // barCodePrintingType = appParameter.ParameterValue; // } //} if (string.IsNullOrEmpty(barCodeTemplate)) { barCodeTemplate = Resources.ConstBarCodeTemplate1; } if (!Resources.ConstBarCodeTemplate6.Equals(barCodeTemplate)) { PrintBarCode.InializePrinting(_barCodeList, barCodeTemplate); } else { var fileName = Resources.ConstBarcodeExcelFile; var printBarCode = new PrintBarCode(); printBarCode.PrintBarcodeHandler( Application.StartupPath + @"\" + fileName, string.Empty, _barCodeList); } SetFocusToProductList(); } catch (Exception exception) { FrmExtendedMessageBox.UnknownErrorMessage( Resources.MsgCaptionUnknownError, exception.Message); } }
private void BtnDeleteClick(object sender, EventArgs e) { if (dgvProduct.CurrentRow == null) { return; } string briefMsg, detailMsg; if (!UserService.AllowToPerform(Resources.PermissionDeleteProduct)) { briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } //string briefMsg, detailMsg; briefMsg = "អំពីការលុប"; detailMsg = Resources.MsgOperationRequestDelete + "\n" + dgvProduct.CurrentRow.Cells["DisplayName"].Value + " ?"; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; if (frmMessageBox.ShowDialog(this) != DialogResult.OK) { return; } } try { _productService.ManageProduct(_productList[dgvProduct.CurrentRow.Index], Resources.OperationRequestDelete); _productList.RemoveAt(dgvProduct.CurrentRow.Index); DisplayPartialPicture( dgvProduct.DisplayedRowCount(true), dgvProduct.FirstDisplayedScrollingRowIndex + dgvProduct.DisplayedRowCount(true), dgvProduct.FirstDisplayedScrollingRowIndex, ScrollEventType.SmallDecrement); UpdateResultInfo(); EnableActionButton(); } catch (Exception) { briefMsg = "អំពីការលុប"; detailMsg = Resources.MsgUnknownError; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } }
private void RefreshIncomeStatementReport() { try { wbsReport.Navigate("about:blank"); if (!UserService.AllowToPerform(Resources.PermissionViewIncomeStatementReport)) { const string briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; var detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } int counter; var startDate = dtpStartDate.Value.ToString("dd/MM/yyyy", AppContext.CultureInfo); var endDate = dtpStopDate.Value.ToString("dd/MM/yyyy", AppContext.CultureInfo); //Sales var saleOrderService = ServiceFactory.GenerateServiceInstance().GenerateSaleOrderService(); var searchCriteria = new List <string> { "SaleOrderDate BETWEEN CONVERT(DATETIME, '" + startDate + "', 103) AND CONVERT(DATETIME, '" + endDate + " 23:59', 103)" }; var saleOrderList = saleOrderService.GetSaleHistoriesOrderByProductCategory(searchCriteria); var saleType = string.Empty; var saleAmount = 0f; var purchaseAmount = 0f; var groupSaleList = new List <List <object> >(); foreach (var saleOrderReport in saleOrderList.Cast <SaleOrderReport>().Where(saleOrderReport => saleOrderReport != null)) { if (!saleOrderReport.CategoryStr.Equals(saleType)) { List <object> groupSale; if (groupSaleList.Count != 0) { counter = groupSaleList.Count; groupSale = groupSaleList[counter - 1]; groupSale.Add(saleAmount); groupSale.Add(purchaseAmount); } saleType = saleOrderReport.CategoryStr; groupSale = new List <object> { saleType }; groupSaleList.Add(groupSale); saleAmount = 0f; purchaseAmount = 0f; } saleAmount += saleOrderReport.AmountSoldInt; //saleAmount += (saleOrderReport.AmountSoldInt * saleOrderReport.ExchangeRate); saleAmount += (saleOrderReport.DepositAmount); //purchaseAmount += saleOrderReport.PurchaseUnitPrice; purchaseAmount += (saleOrderReport.QtySold * saleOrderReport.UnitPriceIn); } if (groupSaleList.Count != 0) { counter = groupSaleList.Count; var groupExpense = groupSaleList[counter - 1]; groupExpense.Add(saleAmount); groupExpense.Add(purchaseAmount); } //Expense var expenseService = ServiceFactory.GenerateServiceInstance().GenerateExpenseService(); searchCriteria = new List <string> { "ExpenseDate BETWEEN CONVERT(DATETIME, '" + startDate + "', 103) AND CONVERT(DATETIME, '" + endDate + "', 103)" }; var expenseList = expenseService.GetExpensesOrderByType(searchCriteria); var expenseType = string.Empty; var expenseAmount = 0f; var groupExpenseList = new List <List <object> >(); foreach (var expense in expenseList.Cast <Expense>().Where(expense => expense != null)) { if (!expense.ExpenseTypeStr.Equals(expenseType)) { List <object> groupExpense; if (groupExpenseList.Count != 0) { counter = groupExpenseList.Count; groupExpense = groupExpenseList[counter - 1]; groupExpense.Add(expenseAmount); } expenseType = expense.ExpenseTypeStr; groupExpense = new List <object> { expenseType }; groupExpenseList.Add(groupExpense); expenseAmount = 0f; } expenseAmount += expense.ExpenseAmountInt; expenseAmount += (expense.ExpenseAmountRiel / expense.ExchangeRate); } if (groupExpenseList.Count != 0) { counter = groupExpenseList.Count; var groupExpense = groupExpenseList[counter - 1]; groupExpense.Add(expenseAmount); } //Write to Excel file var templateIncomeStatementFileName = System.Windows.Forms.Application.StartupPath + @"\" + Resources.ConstIncomeStatementExcelFile; var templateIncomeStatementFileInfo = new FileInfo(templateIncomeStatementFileName); if (!templateIncomeStatementFileInfo.Exists) { const string briefMsg = "អំពីប្រព័ន្ឋ"; var detailMsg = Resources.MsgMissingIncomeStatement; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } var temporaryIncomeStatementFileName = System.Windows.Forms.Application.StartupPath + @"\" + DateTime.Now.Ticks + Resources.ConstIncomeStatementExcelFile; var invoicePeriode = startDate + " ដល់ " + endDate; //Open workbook var excelApplication = new ExcelApplication(); var workBook = excelApplication.Workbooks.Open( templateIncomeStatementFileName, 0, false, 5, false, string.Empty, false, XlPlatform.xlWindows, string.Empty, true, false, 0, true, false, false); //Invoice content var workSheet = (Worksheet)workBook.Worksheets[Resources.ConstSheetIncomeStatement]; //Shop name var rowIndex = 1; var excelRange = workSheet.get_Range("A" + rowIndex, "A" + rowIndex); excelRange.Select(); excelRange.Value2 = "របាយការណ៏ហិរញ្ញវុត្ថុរបស់ក្រុមហ៊ុន " + AppContext.ShopNameLocal; rowIndex = 2; excelRange = workSheet.get_Range("A" + rowIndex, "A" + rowIndex); excelRange.Select(); excelRange.Value2 = "Financial Statement of " + AppContext.ShopName; //Period rowIndex = 3; excelRange = workSheet.get_Range("A" + rowIndex, "A" + rowIndex); excelRange.Select(); excelRange.Value2 = "ពី " + invoicePeriode; //Income rowIndex = 5; counter = 0; var totalPurchaseAmount = 0f; foreach (var saleReport in groupSaleList.Where(saleReport => saleReport != null)) { excelRange = workSheet.get_Range("B" + rowIndex, "B" + rowIndex); excelRange.Select(); excelRange.Value2 = saleReport[0].ToString(); excelRange = workSheet.get_Range("C" + rowIndex, "C" + rowIndex); excelRange.Select(); excelRange.Value2 = "……………………………………."; excelRange = workSheet.get_Range("D" + rowIndex, "D" + rowIndex); excelRange.Select(); excelRange.Value2 = "USD"; excelRange = workSheet.get_Range("E" + rowIndex, "E" + rowIndex); excelRange.Select(); excelRange.Value2 = float.Parse(saleReport[1].ToString()); totalPurchaseAmount += float.Parse(saleReport[2].ToString()); rowIndex += 1; excelRange = workSheet.get_Range("A" + rowIndex, "A" + rowIndex); if (counter == (groupSaleList.Count - 1)) { continue; } excelRange.EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, 1); counter += 1; } //Purchase amount rowIndex += 3; excelRange = workSheet.get_Range("E" + rowIndex, "E" + rowIndex); excelRange.Select(); excelRange.Value2 = totalPurchaseAmount; //Expense rowIndex += 4; counter = 0; foreach (var expenseReport in groupExpenseList.Where(expenseReport => expenseReport != null)) { excelRange = workSheet.get_Range("B" + rowIndex, "B" + rowIndex); excelRange.Select(); excelRange.Value2 = expenseReport[0].ToString(); excelRange = workSheet.get_Range("C" + rowIndex, "C" + rowIndex); excelRange.Select(); excelRange.Value2 = "……………………………………."; excelRange = workSheet.get_Range("D" + rowIndex, "D" + rowIndex); excelRange.Select(); excelRange.Value2 = "USD"; excelRange = workSheet.get_Range("E" + rowIndex, "E" + rowIndex); excelRange.Select(); excelRange.Value2 = expenseReport[1].ToString(); rowIndex += 1; excelRange = workSheet.get_Range("A" + rowIndex, "A" + rowIndex); if (counter == (groupExpenseList.Count - 1)) { continue; } excelRange.EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, 1); counter += 1; } excelRange = workSheet.get_Range("A1", "A1"); excelRange.Select(); workBook.Close( true, temporaryIncomeStatementFileName, System.Reflection.Missing.Value); excelApplication.Quit(); Marshal.ReleaseComObject(excelApplication); GC.Collect(0, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); //Open report wbsReport.BringToFront(); wbsReport.Navigate(temporaryIncomeStatementFileName); } catch (Exception exception) { FrmExtendedMessageBox.UnknownErrorMessage( Resources.MsgCaptionUnknownError, exception.Message); } }
private void RefreshReportStock() { try { if (rdbStockDetail.Checked) { if (!UserService.AllowToPerform(Resources.PermissionViewDetailStockReport)) { const string briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; var detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } } else if (rdbStockShort.Checked) { if (!UserService.AllowToPerform(Resources.PermissionViewStockReport)) { const string briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; var detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } } else { if (!UserService.AllowToPerform(Resources.PermissionViewExpiredProductReport)) { const string briefMsg = "អំពីសិទ្ឋិប្រើប្រាស់"; var detailMsg = Resources.MsgUserPermissionDeny; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } } var searchCriteria = new List <string> { "QtyInStock > 0" }; if (rdbProductExpired.Checked) { searchCriteria.Add( "LastUpdate <= CONVERT(DATETIME, '" + DateTime.Now.AddMonths(-1).ToString("dd/MM/yyyy") + "', 103)"); } var productList = _ProductService.GetObjects(searchCriteria); DataSet dtsProduct = new DtsModels(); var propertyInfos = typeof(Product).GetProperties(); foreach (var objInstance in productList) { var dataRow = dtsProduct.Tables[0].NewRow(); foreach (var propertyInfo in propertyInfos) { dataRow[propertyInfo.Name] = propertyInfo.GetValue(objInstance, null); } dtsProduct.Tables[0].Rows.Add(dataRow); } if ((rdbStockDetail.Checked) || (rdbProductExpired.Checked)) { var csrCatalog = new CsrCatalog(); csrCatalog.SetDataSource(dtsProduct); crvReport.ReportSource = csrCatalog; } else { var csrCatalogShorten = new CsrCatalogShorten(); csrCatalogShorten.SetDataSource(dtsProduct); crvReport.ReportSource = csrCatalogShorten; } } catch (Exception exception) { FrmExtendedMessageBox.UnknownErrorMessage( Resources.MsgCaptionUnknownError, exception.Message); } }