コード例 #1
0
        public void LoadDashboard(DashboardImage _dashboardImage, DashboardViewer dashboardViewer1)
        {
            using (var ctx = new ReportContext())
            {
                string path = LoadToChache(_dashboardImage);

                Dashboard ds = new Dashboard();

                ds.LoadFromXml(path);

                DataSourceCollection dsCollection = ds.DataSources;

                var appConf = new AppConfigIts(ctx.NameOrConnectionString);

                foreach (DashboardSqlDataSource dsSql in dsCollection)
                {
                    ReportUtil.SetParamDataSource(dsSql, appConf);
                }

                dashboardViewer1.Dashboard = ds;
                dashboardViewer1.ReloadData();
            }
        }
コード例 #2
0
        //Improve, cant accept negative in new sales and shouldnt pay more than already payed when editing
        public void SaveDailySalesRecord(LookUpEdit customer, string customerID, string car, LookUpEdit regNum, LookUpEdit servType, TextEdit amount, TextEdit allPayments, DateEdit dateCreated, MemoEdit remarks, string carServTable, string cusPurchaseTable, bool canWrite, BarCheckItem editing, int currentRow, GridView gv, DashboardViewer dbv)
        {
            // gv.CloseEditor();
            // gv.UpdateCurrentRow();
            //  gv.UpdateTotalSummary();
            if (!editing.Checked && !canWrite)
            {
                XtraMessageBox.Show("You dont Have Write Access, Contact Admin", "You cant write", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (customer.EditValue == null)
            {
                XtraMessageBox.Show("Select a Customer from the Customer Drop down list ", "Specify a Car", MessageBoxButtons.OK, MessageBoxIcon.Information);
                customer.Focus();
                return;
            }
            if (regNum.EditValue == null)
            {
                XtraMessageBox.Show("Select a Car from the Car Drop down list ", "Specify a Car", MessageBoxButtons.OK, MessageBoxIcon.Information);
                regNum.Focus();
                return;
            }
            if (servType.EditValue == null)
            {
                XtraMessageBox.Show("Select a Service Type from the Service Type Drop down list ", "Specify a Service Type", MessageBoxButtons.OK, MessageBoxIcon.Information);
                servType.Focus();
                return;
            }


            //if (decimal.Parse(prevAmount.EditValue.ToString()) < 0)
            //{
            //    XtraMessageBox.Show("You cant make negative payments ", "No negative payments allowed", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    prevAmount.Focus();
            //    return;
            //}
            int count = 0;

            foreach (Tuple <bool, int, double, double> values in CustomerPurchaseData.Values)
            {
                if (values.Item1)
                {
                    count++;
                }
            }
            if (count == 0)
            {
                XtraMessageBox.Show("No Product Or service Was selected for this customer,You Want ot go ahead and still Save ?", "No Product selected For Customer", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                return;
            }
            Setup.comm = new SqlCommand();
            Setup.comm.Parameters.Add(new SqlParameter("@CusID", customer.EditValue));
            Setup.comm.Parameters.Add(new SqlParameter("@CarID", regNum.EditValue));
            Setup.comm.Parameters.Add(new SqlParameter("@ServTypeID", servType.EditValue));
            Setup.comm.Parameters.Add(new SqlParameter("@Amount", amount.EditValue));
            Setup.comm.Parameters.Add(new SqlParameter("@Quantity", 1));
            Setup.comm.Parameters.Add(new SqlParameter("@ProductID", 1));

            Setup.comm.Parameters.Add(new SqlParameter("@Discount", 1));
            Setup.comm.Parameters.Add(new SqlParameter("@Remarks", remarks.Text));
            Setup.comm.Parameters.Add(new SqlParameter("@DateCreated", dateCreated.DateTime));

            try
            {
                using (Setup.connx = new SqlConnection(Setup.connString))
                {
                    Setup.connx.Open();
                    if (!Setup.mode[6])
                    {
                        decimal amnt = (decimal)amount.EditValue;
                        if (amnt < 0)
                        {
                            XtraMessageBox.Show("You cant make negative payments ", "No negative payments allowed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            amount.Focus();
                            return;
                        }
                        if (amnt > Setup.sumOfSelectedItems)
                        {
                            amnt = Setup.sumOfSelectedItems;
                            Setup.comm.Parameters["@Amount"].Value = amnt;
                            //XtraMessageBox.Show("Amount entered is greater than amount due for payment ", "Customer Payment greater than Amount Due", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            //amount.Focus();
                            //return;
                        }


                        Setup.comm.CommandText = "select csCusID from etblCarService where csCusID=@CusID and CAST(csDateCreated as DATE)=CAST(@DateCreated as Date)";
                        Setup.comm.Connection  = Setup.connx;
                        Setup.reader           = Setup.comm.ExecuteReader();
                        while (Setup.reader.Read())
                        {
                            if (XtraMessageBox.Show(customer.Text + " Car has already been serviced today, you sure u wanna add another transaction!", "This Customer has been already been today", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                            {
                                return;
                            }
                        }
                        Setup.reader.Close();
                        Setup.comm.Parameters.Add(new SqlParameter("@CreatorID", Setup.userID));
                        Setup.comm.Parameters.Add(new SqlParameter("@CreatedDate", DateTime.Now));

                        //Save customer Details
                        Setup.comm.CommandText = "Insert into etblCarService (csCusID,csStID,csCcID,csremarks,csDateCreated,csCreatorID,csCreatedDate) values(@CusID,@CarID,@ServTypeID,@remarks,@DateCreated,@creatorID,@createdDate);select scope_identity()";
                        Setup.primaryKey       = Convert.ToInt32(Setup.comm.ExecuteScalar());
                        Setup.dataSet.Tables[carServTable].Rows.Add(Setup.primaryKey, customer.EditValue, customer.Text, customerID, car, regNum.Text, servType.Text, remarks.Text, dateCreated.DateTime, Setup.sumOfSelectedItems, amnt, Setup.sumOfSelectedItems - amnt, Setup.UserName);
                        bool added = false;

                        Setup.comm.Parameters.Add(new SqlParameter("@csID", Setup.primaryKey));
                        //Save Customer Purchases
                        Setup.reader.Close();
                        Setup.comm.CommandText = "Insert into etblCustomerPurchase(cpCsID,cpPpID,cpQuantity,cpDiscount) values(@CsID,@ProductID,@Quantity,@Discount)";
                        foreach (int row in CustomerPurchaseData.Keys)
                        {
                            added = CustomerPurchaseData[row].Item1;
                            if (added)
                            {
                                Setup.comm.Parameters["@ProductID"].Value = Setup.dataSet.Tables[cusPurchaseTable].Rows[row].ItemArray[0];
                                Setup.comm.Parameters["@Quantity"].Value  = CustomerPurchaseData[row].Item2;

                                Setup.comm.Parameters["@Discount"].Value = CustomerPurchaseData[row].Item3;
                                Setup.comm.ExecuteNonQuery();
                            }
                        }

                        //Save customer Payments
                        Setup.comm.CommandText = "Insert into etblCustomerPayments(cuspaycsID,cuspayAmount,cusPayDateCreated,cusPayCreatorID,cusPayCreatedDate) values(@csID,@Amount,@DateCreated,@CreatorID,@CreatedDate)";
                        Setup.comm.ExecuteNonQuery();

                        XtraMessageBox.Show(customer.Text + " Saved Sussusfully", "Transaction Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        decimal totalPaid   = Convert.ToDecimal(Setup.dataSet.Tables[carServTable].Rows[currentRow].ItemArray[10]);
                        decimal prevAmntDue = Convert.ToDecimal(Setup.dataSet.Tables[carServTable].Rows[currentRow].ItemArray[9]);
                        decimal amnt        = (decimal)amount.EditValue;
                        decimal payments    = totalPaid + amnt;
                        decimal change      = payments - Setup.sumOfSelectedItems;


                        if ((amnt < 0) && Setup.sumOfSelectedItems < payments)
                        {
                            XtraMessageBox.Show("Negative amount only means refund of money to customers and as such, it is expected that Change after refund be zero", "Change after a refund Incorrect", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            amount.Focus();
                            return;
                        }

                        if (payments < 0)
                        {
                            XtraMessageBox.Show("You cant refund below amount customer has already paid", "Refund is Ambigious", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            amount.Focus();
                            return;
                        }

                        if (payments > Setup.sumOfSelectedItems)
                        {
                            if ((amnt - change) >= 0)
                            {
                                amnt -= change;
                                Setup.comm.Parameters["@Amount"].Value = amnt;
                            }
                            else
                            {
                                XtraMessageBox.Show("Change to give Customer is greater than amount customer paid, Enter negative values in case of a refund", "Customer Change is Ambigious", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                amount.Focus();
                                return;
                            }
                        }
                        Setup.comm.Parameters.Add(new SqlParameter("@EditorID", Setup.userID));
                        Setup.comm.Parameters.Add(new SqlParameter("@EditedDate", DateTime.Now));
                        Setup.comm.Parameters.Add(new SqlParameter("@ID", Setup.dataSet.Tables[carServTable].Rows[currentRow].ItemArray[0]));

                        Setup.comm.Parameters.Add(new SqlParameter("@UserName", Setup.dataSet.Tables[carServTable].Rows[currentRow].ItemArray[12]));
                        Setup.comm.CommandText = "select csCusID from etblCarService where csCusID=@CusID and CAST(csDateCreated as DATE)=CAST(@DateCreated as Date) and csID!=@ID";
                        Setup.comm.Connection  = Setup.connx;
                        Setup.reader           = Setup.comm.ExecuteReader();
                        while (Setup.reader.Read())
                        {
                            if (XtraMessageBox.Show(customer.Text + " Car has already been serviced today, you sure u wanna add another transaction!", "This Customer has been already been today", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                            {
                                return;
                            }
                        }
                        Setup.reader.Close();
                        Setup.comm.CommandText = "Update etblCarService set csCusID=@CusID,csStID=@ServTypeID,csCcID=@CarID,csremarks=@remarks,csEditorID=@EditorID,csEditedDate=@EditedDate where csID=@ID";
                        Setup.comm.ExecuteNonQuery();
                        allPayments.EditValue = totalPaid + amnt;
                        Setup.dataSet.Tables[carServTable].Rows[currentRow].ItemArray = new object[] { Setup.comm.Parameters["@ID"].Value, customer.EditValue, customer.Text, customerID, car, regNum.Text, servType.Text, remarks.Text, dateCreated.DateTime, Setup.sumOfSelectedItems, totalPaid + amnt, (Setup.sumOfSelectedItems - (totalPaid + amnt)), Setup.comm.Parameters["@Username"].Value };

                        //Delete previous purchases
                        Setup.comm.CommandText = "Delete from etblCustomerPurchase where cpCsID=@ID";
                        Setup.comm.ExecuteNonQuery();
                        bool added = false;

                        //Save Customer Purchases

                        Setup.comm.CommandText = "Insert into etblCustomerPurchase(cpCsID,cpPpID,cpQuantity,cpDiscount) values(@ID,@ProductID,@Quantity,@Discount)";
                        foreach (int row in CustomerPurchaseData.Keys)
                        {
                            added = CustomerPurchaseData[row].Item1;
                            if (added)
                            {
                                Setup.comm.Parameters["@ProductID"].Value = Setup.dataSet.Tables[cusPurchaseTable].Rows[row].ItemArray[0];
                                Setup.comm.Parameters["@Quantity"].Value  = CustomerPurchaseData[row].Item2;

                                Setup.comm.Parameters["@Discount"].Value = CustomerPurchaseData[row].Item3;
                                Setup.comm.ExecuteNonQuery();
                            }
                        }

                        //Add new Customer Payments if any
                        if (amnt != 0)
                        {
                            Setup.comm.CommandText = "Insert into etblCustomerPayments(cuspaycsID,cuspayAmount,cusPayDateCreated,cusPayCreatorID,cusPayCreatedDate) values(@ID,@Amount,@DateCreated,@EditorID,@EditedDate);select scope_identity()";
                            Setup.comm.ExecuteNonQuery();
                        }
                        amount.EditValue = default(decimal);
                        XtraMessageBox.Show(customer.Text + " Updated Sussusfully", "Car Servicing Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        //Report a refund
                        if (amnt < 0 || Setup.sumOfSelectedItems < prevAmntDue)
                        {
                            Setup.comm.Parameters.Add(new SqlParameter("@Type", amnt < 0 ? "MONEY" : "PRODUCT OR SERVICE"));
                            Setup.comm.Parameters.Add(new SqlParameter("@rfdAmount", amnt < 0 ? Math.Abs(amnt) :prevAmntDue - Setup.sumOfSelectedItems));
                            Setup.comm.CommandText = "Insert into etblRefunds(rfdAmount,rfdCusID,rfdType,rfdDateCreated,rfdCreatorID) values(@rfdAmount,@CusID,@Type,@EditedDate,@EditorID)";
                            Setup.comm.ExecuteNonQuery();
                        }
                    }
                    //amountRecieved.EditValue = default(decimal);


                    //Load Invoice

                    Cursor.Current = Cursors.AppStarting;
                    if (dbv.Dashboard != null)
                    {
                        dbv.ReloadData();
                    }
                    PrintSingle = true;
                    report      = new UmitechXtraReport();
                    report.Parameters[0].Visible = false;
                    report.Parameters[0].Value   = customer.EditValue;
                    printTool = new ReportPrintTool(report);
                    printTool.ShowRibbonPreviewDialog();
                    PrintSingle    = false;
                    Cursor.Current = Cursors.Default;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("OOPs! cud not connect to server now Contact HR\r\n" + ex.Message, "Notification", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }