コード例 #1
0
ファイル: InvoiceEdit.xaml.cs プロジェクト: OneSmugPug/Denovo
        private void LoadInvoice()
        {
            try
            {
                using (var conn = DBUtils.GetDBConnection())
                {
                    conn.Open();

                    var sql = string.Empty;

                    if (!selectedEmpCode.Equals(string.Empty))
                    {
                        sql = "SELECT Date, Client, [Bill Amount (R)], [Drawing Fee (%)], [DF Amount (R)], [Commission Due (R)], Paid FROM Invoices WHERE " +
                              " Code = '" + selectedEmpCode + "' AND [Invoice Number] = '" + invNumber + "'";
                    }
                    else
                    {
                        sql = "SELECT Date, Client, [Bill Amount (R)], [Drawing Fee (%)], [DF Amount (R)], [Commission Due (R)], Paid FROM Invoices WHERE " +
                              "[Invoice Number] = '" + invNumber + "'";
                    }

                    using (var da = new SqlDataAdapter(sql, conn))
                    {
                        dt = new DataTable();
                        da.Fill(dt);
                    }

                    if (dt.Rows.Count > 0)
                    {
                        DataRow row = dt.Rows[0];

                        foreach (string item in CbClient.Items)
                        {
                            if (row["Client"].ToString().Equals(item.Split('-')[0].Trim()))
                            {
                                CbClient.SelectedItem = item;
                            }
                        }

                        if (decimal.TryParse(row["Bill Amount (R)"].ToString().Replace(",", "").Replace(".", "").TrimStart('0'), out decimal billAmountResult))
                        {
                            billAmountResult  /= 100;
                            billAmount         = billAmountResult;
                            TxtBillAmount.Text = billAmount.ToString("N2", nfi);
                        }

                        if (decimal.TryParse(row["Drawing Fee (%)"].ToString().Replace(",", "").Replace(".", "").TrimStart('0'), out decimal drawingFeeResult))
                        {
                            drawingFeeResult  /= 100;
                            drawingFee         = drawingFeeResult;
                            TxtDrawingFee.Text = drawingFee.ToString("P", nfi);
                        }

                        if (decimal.TryParse(row["DF Amount (R)"].ToString().Replace(",", "").Replace(".", "").TrimStart('0'), out decimal dfAmountResult))
                        {
                            dfAmountResult  /= 100;
                            dfAmount         = dfAmountResult;
                            TxtDFAmount.Text = dfAmount.ToString("N2", nfi);
                        }

                        if (decimal.TryParse(row["Commission Due (R)"].ToString().Replace(",", "").Replace(".", "").TrimStart('0'), out decimal commDueResult))
                        {
                            commDueResult  /= 100;
                            commDue         = commDueResult;
                            TxtCommDue.Text = commDue.ToString("N2", nfi);
                        }

                        DtpDate.SelectedDate = DateTime.Parse(row["Date"].ToString());

                        if (!row["Paid"].Equals("Yes"))
                        {
                            CbPaid.IsChecked = false;
                        }
                        else
                        {
                            CbPaid.IsChecked = true;
                        }

                        CalculateCommissionDue();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #2
0
ファイル: InvoiceEdit.xaml.cs プロジェクト: OneSmugPug/Denovo
        private void BtnDone_Click(object sender, RoutedEventArgs e)
        {
            if (!TxtInvoiceNumber.Text.Equals(string.Empty))
            {
                StringBuilder sb = new StringBuilder().Append("Are you sure you want to continue?");

                if (MessageBox.Show(sb.ToString(), "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    if (USER.GetAccessLevel() == 1 || (USER.GetAccessLevel() == 2 && selectedEmpCode.Equals(string.Empty)))
                    {
                        try
                        {
                            using (var conn = DBUtils.GetDBConnection())
                            {
                                conn.Open();

                                using (var cmd = new SqlCommand("UPDATE Invoices SET Date = @Date, Client = @Client, [Bill Amount (R)] = @BillAmount, [Drawing Fee (%)] = @DrawFee, "
                                                                + "[DF Amount (R)] = @DFAmount, [Commission Due (R)] = @CommDue, [Company Comm (R)] = @CompComm, [Personal Comm (R)] = @PersonalComm, Finalized = @Finalized, Paid = @Paid "
                                                                + "WHERE Code = @Code AND [Invoice Number] = @InvNum", conn))
                                {
                                    cmd.Parameters.AddWithValue("@Code", USER.GetCode());
                                    cmd.Parameters.AddWithValue("@Date", DtpDate.SelectedDate.Value.Date);
                                    cmd.Parameters.AddWithValue("@Client", CbClient.SelectedItem.ToString().Split('-')[0].Trim());
                                    cmd.Parameters.AddWithValue("@InvNum", TxtInvoiceNumber.Text.Trim());
                                    cmd.Parameters.AddWithValue("@BillAmount", billAmount);
                                    cmd.Parameters.AddWithValue("@DrawFee", drawingFee);
                                    cmd.Parameters.AddWithValue("@DFAmount", dfAmount);
                                    cmd.Parameters.AddWithValue("@CommDue", commDue);
                                    cmd.Parameters.AddWithValue("@CompComm", companyComm);
                                    cmd.Parameters.AddWithValue("@PersonalComm", personalComm);

                                    if (!(bool)CbFinalized.IsChecked)
                                    {
                                        cmd.Parameters.AddWithValue("@Finalized", "No");
                                    }
                                    else
                                    {
                                        cmd.Parameters.AddWithValue("@Finalized", "Yes");
                                    }

                                    if (!(bool)CbPaid.IsChecked)
                                    {
                                        cmd.Parameters.AddWithValue("@Paid", "No");
                                    }
                                    else
                                    {
                                        cmd.Parameters.AddWithValue("@Paid", "Yes");
                                    }

                                    cmd.ExecuteNonQuery();

                                    DialogResult = true;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    else if (USER.GetAccessLevel() == 2 && !selectedEmpCode.Equals(string.Empty))
                    {
                        try
                        {
                            using (var conn = DBUtils.GetDBConnection())
                            {
                                conn.Open();

                                using (var cmd = new SqlCommand("UPDATE Invoices SET Date = @Date, Client = @Client, [Bill Amount (R)] = @BillAmount, [Drawing Fee (%)] = @DrawFee, "
                                                                + "[DF Amount (R)] = @DFAmount, [Commission Due (R)] = @CommDue, [Company Comm (R)] = @CompComm, [Personal Comm (R)] = @PersonalComm, Finalized = @Finalized, Paid = @Paid "
                                                                + "WHERE Code = @Code AND [Invoice Number] = @InvNum", conn))
                                {
                                    cmd.Parameters.AddWithValue("@Code", selectedEmpCode);
                                    cmd.Parameters.AddWithValue("@Date", DtpDate.SelectedDate.Value.Date);
                                    cmd.Parameters.AddWithValue("@Client", CbClient.SelectedItem.ToString().Split('-')[0].Trim());
                                    cmd.Parameters.AddWithValue("@InvNum", TxtInvoiceNumber.Text.Trim());
                                    cmd.Parameters.AddWithValue("@BillAmount", billAmount);
                                    cmd.Parameters.AddWithValue("@DrawFee", drawingFee);
                                    cmd.Parameters.AddWithValue("@DFAmount", dfAmount);
                                    cmd.Parameters.AddWithValue("@CommDue", commDue);
                                    cmd.Parameters.AddWithValue("@CompComm", companyComm);
                                    cmd.Parameters.AddWithValue("@PersonalComm", personalComm);

                                    if (!(bool)CbFinalized.IsChecked)
                                    {
                                        cmd.Parameters.AddWithValue("@Finalized", "No");
                                    }
                                    else
                                    {
                                        cmd.Parameters.AddWithValue("@Finalized", "Yes");
                                    }

                                    if (!(bool)CbPaid.IsChecked)
                                    {
                                        cmd.Parameters.AddWithValue("@Paid", "No");
                                    }
                                    else
                                    {
                                        cmd.Parameters.AddWithValue("@Paid", "Yes");
                                    }

                                    cmd.ExecuteNonQuery();

                                    DialogResult = true;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                }
            }
        }