private void GeneratePayment(dsCore ds)
        {
            dsCore dt = new dsCore();

            dt.EnforceConstraints = false;

            // copy master record
            dt.Orders.Rows.Add(ds.Orders[0].ItemArray);
            // ubah jenis transaksi
            dt.Orders[0].ParentID   = ds.Orders[0].ID;
            dt.Orders[0].OrderNo    = DbHelper.GenerateNewOrderID(TransactionTypes.TX_PURCHASE_PAYMENT, dt.Orders[0].OrderDate.Year);
            dt.Orders[0].OrderType  = TransactionTypes.TX_PURCHASE_PAYMENT;
            dt.Orders[0].OrderValue = Convert.ToDouble(c1NumericEdit1.Value);
            // detail payment
            dsCore.OrderDetailsRow row = dt.OrderDetails.NewOrderDetailsRow();
            row.OrderID     = dt.Orders[0].ID;
            row.ReferenceID = InvoiceID;
            row.UnitPrice   = Convert.ToDouble(c1NumericEdit1.Value);
            row.Quantity    = 1;
            row.TaxPct      = 0;
            if (!dt.Orders[0].IsRemarksNull())
            {
                row.Remarks = ds.Orders[0].Remarks;
            }
            dt.OrderDetails.AddOrderDetailsRow(row);

            // persist changes to database
            daOrders1.Update(dt.Orders);
            daOrderDetails1.Update(dt.OrderDetails);

            // remember result
            PaymentID  = dt.Orders[0].ID;
            PaymentNum = dt.Orders[0].OrderNo;
        }
Beispiel #2
0
 private void c1Combo2_SelectedValueChanged(object sender, EventArgs e)
 {
     if (txMode == DataEntryModes.Add)
     {
         try
         {
             // get data
             dsCore                   ds = new dsCore();
             OrdersTableAdapter       od = new OrdersTableAdapter();
             OrderDetailsTableAdapter ta = new OrderDetailsTableAdapter();
             ds.EnforceConstraints = false;
             od.Connection         = AppHelper.GetDbConnection();
             od.FillByID(ds.Orders, (int)c1Combo2.SelectedValue);
             ta.Connection = AppHelper.GetDbConnection();
             ta.FillNotCompleted(ds.OrderDetails, (int)c1Combo2.SelectedValue);
             // clear grid
             dsCore1.OrderDetails.Clear();
             // fill grid with new data
             _grid.Redraw = false;
             DataRowView dv = (DataRowView)this.BindingContext[dsCore1, "Orders"].Current;
             dv["CompanyID"]  = ds.Orders[0].CompanyID;
             dv["CurrencyID"] = ds.Orders[0].CurrencyID;
             if (!ds.Orders[0].IsCompanyIDNull())
             {
                 c1Combo1.SelectedValue = ds.Orders[0].CompanyID;
             }
             if (!ds.Orders[0].IsCurrencyIDNull())
             {
                 c1Combo3.SelectedValue = ds.Orders[0].CurrencyID;
             }
             foreach (dsCore.OrderDetailsRow src in ds.OrderDetails.Rows)
             {
                 dsCore.OrderDetailsRow row = dsCore1.OrderDetails.NewOrderDetailsRow();
                 row.OrderID     = (int)dv["ID"];
                 row.ItemID      = src.ItemID;
                 row.ItemCode    = src.ItemCode;
                 row.ItemName    = src.ItemName;
                 row.Quantity    = src.Quantity;
                 row.UnitPrice   = src.UnitPrice;
                 row.TaxPct      = src.TaxPct;
                 row.Remarks     = src.Remarks;
                 row.MeasureCode = src.MeasureCode;
                 dsCore1.OrderDetails.AddOrderDetailsRow(row);
             }
             // redraw grid
             _grid.Redraw = true;
             _grid.Refresh();
             // recalculate order value
             c1Label1.Value = CountDetails();
         }
         catch (Exception ex)
         {
             // textfile logging
             Logger.ErrorRoutine(ex);
             // screen logging
             RibbonMessageBox.Show("ERROR Retrieving Detail Data: \n" + ex.Message,
                                   Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
 }
        private void GenerateInvoice(dsCore ds)
        {
            dsCore dt = new dsCore();

            dt.EnforceConstraints = false;

            // copy master record
            dt.Orders.Rows.Add(ds.Orders[0].ItemArray);
            // copy juga detail record dari main dataset
            for (int i = 0; i < ds.OrderDetails.Rows.Count; i++)
            {
                dt.OrderDetails.Rows.Add(ds.OrderDetails.Rows[i].ItemArray);
            }
            // ubah jenis transaksi
            dt.Orders[0].ParentID   = ds.Orders[0].ID;
            dt.Orders[0].OrderNo    = DbHelper.GenerateNewOrderID(TransactionTypes.TX_PURCHASE_INVOICE, dt.Orders[0].OrderDate.Year);
            dt.Orders[0].OrderType  = TransactionTypes.TX_PURCHASE_INVOICE;
            dt.Orders[0].OrderValue = ds.Orders[0].OrderValue;
            // persist changes to database
            daOrders1.Update(dt.Orders);
            daOrderDetails1.Update(dt.OrderDetails);
            // remember result
            InvoiceID  = dt.Orders[0].ID;
            InvoiceNum = dt.Orders[0].OrderNo;
        }
Beispiel #4
0
 private void c1Combo1_SelectedValueChanged(object sender, EventArgs e)
 {
     if (txMode == DataEntryModes.Add)
     {
         try
         {
             // prevent redraw
             _grid.Redraw = false;
             // get data
             dsCore             ds = new dsCore();
             OrdersTableAdapter od = new OrdersTableAdapter();
             ds.EnforceConstraints = false;
             od.Connection         = AppHelper.GetDbConnection();
             od.FillOutstandingSalesInvoices(ds.Orders, (int)c1Combo1.SelectedValue);
             // clear grid
             dsCore1.OrderDetails.Clear();
             // fill grid with new data
             DataRowView dv = (DataRowView)this.BindingContext[dsCore1, "Orders"].Current;
             foreach (dsCore.OrdersRow src in ds.Orders.Rows)
             {
                 dsCore.OrderDetailsRow row = dsCore1.OrderDetails.NewOrderDetailsRow();
                 row.OrderID        = (int)dv["ID"];
                 row.ReferenceID    = src.ID;
                 row.ReferenceNo    = src.OrderNo;
                 row.ReferenceDate  = src.OrderDate;
                 row.ReferenceValue = src.OutstandingValue;
                 row.UnitPrice      = src.OutstandingValue;
                 row.Quantity       = 1;
                 row.TaxPct         = 0;
                 if (!src.IsRemarksNull())
                 {
                     row.Remarks = src.Remarks;
                 }
                 dsCore1.OrderDetails.AddOrderDetailsRow(row);
             }
             // recalculate
             CountDetails();
             // redraw grid
             _grid.Redraw = true;
             _grid.Refresh();
         }
         catch (Exception ex)
         {
             // textfile logging
             Logger.ErrorRoutine(ex);
             // screen logging
             RibbonMessageBox.Show("ERROR Retrieving Detail Data: \n" + ex.Message,
                                   Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
 }
 public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) {
     dsCore ds = new dsCore();
     global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType();
     global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence();
     global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny();
     any.Namespace = ds.Namespace;
     sequence.Items.Add(any);
     type.Particle = sequence;
     global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
     if (xs.Contains(dsSchema.TargetNamespace)) {
         global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
         global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
         try {
             global::System.Xml.Schema.XmlSchema schema = null;
             dsSchema.Write(s1);
             for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext(); ) {
                 schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                 s2.SetLength(0);
                 schema.Write(s2);
                 if ((s1.Length == s2.Length)) {
                     s1.Position = 0;
                     s2.Position = 0;
                     for (; ((s1.Position != s1.Length) 
                                 && (s1.ReadByte() == s2.ReadByte())); ) {
                         ;
                     }
                     if ((s1.Position == s1.Length)) {
                         return type;
                     }
                 }
             }
         }
         finally {
             if ((s1 != null)) {
                 s1.Close();
             }
             if ((s2 != null)) {
                 s2.Close();
             }
         }
     }
     xs.Add(dsSchema);
     return type;
 }
Beispiel #6
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            // Validate all required field(s)
            if (!ValidateUserInput())
            {
                return;
            }

            // if you get here, it means that all user input has been validated
            Cursor = Cursors.AppStarting;

            try
            {
                // End editing
                BindingContext[dsCore1, "Orders"].EndCurrentEdit();
                BindingContext[dsCore1, "OrderDetails"].EndCurrentEdit();

                // There are changes that need to be made, so attempt to update the datasource by
                // calling the update method and passing the dataset and any parameters.
                if (txMode == DataEntryModes.Add)
                {
                    // copy master record dari main dataset
                    // harus dilakukan krena main dataset sebelumnya sudah
                    // AcceptChanges padahal belum diupdate ke database
                    dsChanges = new dsCore();
                    dsChanges.EnforceConstraints = false;
                    dsChanges.Orders.Rows.Add(((DataRowView)this.BindingContext[dsCore1, "Orders"].Current).Row.ItemArray);
                    // persist changes to database
                    daOrders1.Update(dsChanges.Orders);
                    // inform user, successful
                    RibbonMessageBox.Show("Data SUCCESFULLY saved to database",
                                          Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                }
                else
                {
                    // persist changes to database
                    daOrders1.Update(dsCore1.Orders);
                    // inform user for successful update
                    RibbonMessageBox.Show("Changes SUCCESFULLY saved to database",
                                          Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                // success, close form
                btnClose.PerformClick();
            }
            catch (SqlException ex)
            {
                // textfile logging
                Logger.ErrorRoutine(ex);

                // screen logging
                if (ex.Number != 2601)
                {
                    RibbonMessageBox.Show("ERROR Saving Data: \n" + ex.Message,
                                          Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    RibbonMessageBox.Show("ERROR Saving Data:\n" +
                                          "Document number [" + c1TextBox1.Text + "]already existed in database\n" +
                                          "Please change this document number and try saving again.",
                                          Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex)
            {
                // textfile logging
                Logger.ErrorRoutine(ex);

                // screen logging
                RibbonMessageBox.Show("ERROR Saving Data: \n" + ex.Message,
                                      Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            Cursor = Cursors.Default;
        }
 public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs) {
     global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType();
     global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence();
     dsCore ds = new dsCore();
     global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny();
     any1.Namespace = "http://www.w3.org/2001/XMLSchema";
     any1.MinOccurs = new decimal(0);
     any1.MaxOccurs = decimal.MaxValue;
     any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
     sequence.Items.Add(any1);
     global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny();
     any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1";
     any2.MinOccurs = new decimal(1);
     any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
     sequence.Items.Add(any2);
     global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute();
     attribute1.Name = "namespace";
     attribute1.FixedValue = ds.Namespace;
     type.Attributes.Add(attribute1);
     global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute();
     attribute2.Name = "tableTypeName";
     attribute2.FixedValue = "CurrenciesDataTable";
     type.Attributes.Add(attribute2);
     type.Particle = sequence;
     global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
     if (xs.Contains(dsSchema.TargetNamespace)) {
         global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
         global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
         try {
             global::System.Xml.Schema.XmlSchema schema = null;
             dsSchema.Write(s1);
             for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext(); ) {
                 schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                 s2.SetLength(0);
                 schema.Write(s2);
                 if ((s1.Length == s2.Length)) {
                     s1.Position = 0;
                     s2.Position = 0;
                     for (; ((s1.Position != s1.Length) 
                                 && (s1.ReadByte() == s2.ReadByte())); ) {
                         ;
                     }
                     if ((s1.Position == s1.Length)) {
                         return type;
                     }
                 }
             }
         }
         finally {
             if ((s1 != null)) {
                 s1.Close();
             }
             if ((s2 != null)) {
                 s2.Close();
             }
         }
     }
     xs.Add(dsSchema);
     return type;
 }
 public virtual int Update(dsCore.ItemsDataTable dataTable) {
     return this.Adapter.Update(dataTable);
 }
 public virtual int FillByID(dsCore.ItemsDataTable dataTable, int p1) {
     this.Adapter.SelectCommand = this.CommandCollection[3];
     this.Adapter.SelectCommand.Parameters[0].Value = ((int)(p1));
     if ((this.ClearBeforeFill == true)) {
         dataTable.Clear();
     }
     int returnValue = this.Adapter.Fill(dataTable);
     return returnValue;
 }
 public virtual int Update(dsCore dataSet) {
     return this.Adapter.Update(dataSet, "Currencies");
 }
 public virtual int FillDeveloper(dsCore.CompaniesDataTable dataTable) {
     this.Adapter.SelectCommand = this.CommandCollection[5];
     if ((this.ClearBeforeFill == true)) {
         dataTable.Clear();
     }
     int returnValue = this.Adapter.Fill(dataTable);
     return returnValue;
 }
 public virtual int Update(dsCore dataSet) {
     return this.Adapter.Update(dataSet, "Warehouses");
 }
 public virtual int Update(dsCore.WarehousesDataTable dataTable) {
     return this.Adapter.Update(dataTable);
 }
 public virtual int Update(dsCore dataSet) {
     return this.Adapter.Update(dataSet, "UnitMeasures");
 }
 public virtual int Update(dsCore.UnitMeasuresDataTable dataTable) {
     return this.Adapter.Update(dataTable);
 }
 public virtual int FillActive(dsCore.CurrenciesDataTable dataTable) {
     this.Adapter.SelectCommand = this.CommandCollection[1];
     if ((this.ClearBeforeFill == true)) {
         dataTable.Clear();
     }
     int returnValue = this.Adapter.Fill(dataTable);
     return returnValue;
 }
 public virtual int Update(dsCore.CurrenciesDataTable dataTable) {
     return this.Adapter.Update(dataTable);
 }
 public virtual int Update(dsCore.OrderDetailsDataTable dataTable) {
     return this.Adapter.Update(dataTable);
 }
 public virtual int FillByCode(dsCore.ItemsDataTable dataTable, string p1) {
     this.Adapter.SelectCommand = this.CommandCollection[2];
     if ((p1 == null)) {
         throw new global::System.ArgumentNullException("p1");
     }
     else {
         this.Adapter.SelectCommand.Parameters[0].Value = ((string)(p1));
     }
     if ((this.ClearBeforeFill == true)) {
         dataTable.Clear();
     }
     int returnValue = this.Adapter.Fill(dataTable);
     return returnValue;
 }
 public virtual int Update(dsCore dataSet) {
     return this.Adapter.Update(dataSet, "OrderDetails");
 }
 public virtual int FillDenormalized(dsCore.ItemsDataTable dataTable) {
     this.Adapter.SelectCommand = this.CommandCollection[4];
     if ((this.ClearBeforeFill == true)) {
         dataTable.Clear();
     }
     int returnValue = this.Adapter.Fill(dataTable);
     return returnValue;
 }
 public virtual int FillOutstandingSalesInvoices(dsCore.OrdersDataTable dataTable, global::System.Nullable<int> p1) {
     this.Adapter.SelectCommand = this.CommandCollection[10];
     if ((p1.HasValue == true)) {
         this.Adapter.SelectCommand.Parameters[0].Value = ((int)(p1.Value));
     }
     else {
         this.Adapter.SelectCommand.Parameters[0].Value = global::System.DBNull.Value;
     }
     if ((this.ClearBeforeFill == true)) {
         dataTable.Clear();
     }
     int returnValue = this.Adapter.Fill(dataTable);
     return returnValue;
 }
 public virtual int Update(dsCore dataSet) {
     return this.Adapter.Update(dataSet, "Items");
 }
 public virtual int FillPurchaseInvoiceAll(dsCore.OrdersDataTable dataTable) {
     this.Adapter.SelectCommand = this.CommandCollection[13];
     if ((this.ClearBeforeFill == true)) {
         dataTable.Clear();
     }
     int returnValue = this.Adapter.Fill(dataTable);
     return returnValue;
 }
        private void btnSave_Click(object sender, EventArgs e)
        {
            // Validate all required field(s)
            if (!ValidateUserInput())
            {
                return;
            }

            // if you get here, it means that all user input has been validated
            Cursor = Cursors.AppStarting;

            try
            {
                // End editing
                BindingContext[dsCore1, "Orders"].EndCurrentEdit();
                BindingContext[dsCore1, "OrderDetails"].EndCurrentEdit();

                // There are changes that need to be made, so attempt to update the datasource by
                // calling the update method and passing the dataset and any parameters.
                if (txMode == DataEntryModes.Add)
                {
                    // copy master record dari main dataset
                    // harus dilakukan krena main dataset sebelumnya sudah
                    // AcceptChanges padahal belum diupdate ke database
                    dsChanges = new dsCore();
                    dsChanges.EnforceConstraints = false;
                    dsChanges.Orders.Rows.Add(((DataRowView)this.BindingContext[dsCore1, "Orders"].Current).Row.ItemArray);

                    // copy juga detail record dari main dataset
                    for (int i = 0; i < dsCore1.OrderDetails.Rows.Count; i++)
                    {
                        dsChanges.OrderDetails.Rows.Add(dsCore1.OrderDetails.Rows[i].ItemArray);
                    }

                    // persist changes to database
                    daOrders1.Update(dsChanges.Orders);
                    daOrderDetails1.Update(dsChanges.OrderDetails);

                    // only generate invoice
                    GenerateInvoice(dsChanges);

                    // generate payment record for cash payment
                    if (radioButton1.Checked || Convert.ToDouble(c1NumericEdit1.Value) > 0)
                    {
                        GeneratePayment(dsChanges);
                    }

                    // inform user, successful
                    DialogResult dr = RibbonMessageBox.Show("Data SUCCESFULLY saved to database\n" +
                                                            (InvoiceID < 0 ? "" : "New Invoice Voucher [" + InvoiceNum + "] created automatically\n") +
                                                            (PaymentID < 0 ? "" : "New Payment Voucher [" + PaymentNum + "] created automatically\n") +
                                                            "Do you want to print this document?\n",
                                                            Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    // ask user for voucher print
                    if (dr == DialogResult.Yes)
                    {
                        Cursor = Cursors.AppStarting;
                        Form fx = new frmReportViewer1(ReportHelper1.LoadPurchaseOrderForm(c1TextBox1.Text));
                        fx.WindowState = FormWindowState.Maximized;
                        fx.ShowDialog();
                        Cursor = Cursors.Default;
                    }
                }
                else
                {
                    // persist changes to database
                    daOrders1.Update(dsCore1.Orders);
                    daOrderDetails1.Update(dsCore1.OrderDetails);

                    // inform user for successful update
                    RibbonMessageBox.Show("Changes SUCCESFULLY saved to database",
                                          Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                // success, close form
                btnClose.PerformClick();
            }
            catch (SqlException ex)
            {
                // textfile logging
                Logger.ErrorRoutine(ex);

                // screen logging
                if (ex.Number != 2601)
                {
                    RibbonMessageBox.Show("ERROR Saving Data: \n" + ex.Message,
                                          Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    RibbonMessageBox.Show("ERROR Saving Data:\n" +
                                          "Document number [" + c1TextBox1.Text + "]already existed in database\n" +
                                          "Please change this document number and try saving again.",
                                          Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex)
            {
                // textfile logging
                Logger.ErrorRoutine(ex);

                // screen logging
                RibbonMessageBox.Show("ERROR Saving Data: \n" + ex.Message,
                                      Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            Cursor = Cursors.Default;
        }
 public virtual int FillSalesQuotation(dsCore.OrdersDataTable dataTable, global::System.Nullable<global::System.DateTime> date1, global::System.Nullable<global::System.DateTime> date2) {
     this.Adapter.SelectCommand = this.CommandCollection[24];
     if ((date1.HasValue == true)) {
         this.Adapter.SelectCommand.Parameters[0].Value = ((System.DateTime)(date1.Value));
     }
     else {
         this.Adapter.SelectCommand.Parameters[0].Value = global::System.DBNull.Value;
     }
     if ((date2.HasValue == true)) {
         this.Adapter.SelectCommand.Parameters[1].Value = ((System.DateTime)(date2.Value));
     }
     else {
         this.Adapter.SelectCommand.Parameters[1].Value = global::System.DBNull.Value;
     }
     if ((this.ClearBeforeFill == true)) {
         dataTable.Clear();
     }
     int returnValue = this.Adapter.Fill(dataTable);
     return returnValue;
 }
 public virtual int FillSalesQuotationAll(dsCore.OrdersDataTable dataTable) {
     this.Adapter.SelectCommand = this.CommandCollection[25];
     if ((this.ClearBeforeFill == true)) {
         dataTable.Clear();
     }
     int returnValue = this.Adapter.Fill(dataTable);
     return returnValue;
 }
        private void btnSave_Click(object sender, EventArgs e)
        {
            // Validate all required field(s)
            if (!ValidateUserInput())
            {
                return;
            }

            // if you get here, it means that all user input has been validated
            Cursor = Cursors.AppStarting;

            try
            {
                // End editing
                BindingContext[dsCore1, "Orders"].EndCurrentEdit();
                BindingContext[dsCore1, "OrderDetails"].EndCurrentEdit();


                // Validaton Check order detail item -> by K
                if (dsCore1.OrderDetails.Rows.Count == 0)
                {
                    RibbonMessageBox.Show("No item inventory in this order\n" +
                                          "Please input item at least one item\n",
                                          Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                // End Validation -> by K

                // There are changes that need to be made, so attempt to update the datasource by
                // calling the update method and passing the dataset and any parameters.
                if (txMode == DataEntryModes.Add)
                {
                    // copy master record dari main dataset
                    // harus dilakukan krena main dataset sebelumnya sudah
                    // AcceptChanges padahal belum diupdate ke database
                    dsChanges = new dsCore();
                    dsChanges.EnforceConstraints = false;

                    // Possible NULL value dataRowView .:By K:.
                    var dataRowView = (DataRowView)BindingContext[dsCore1, "Orders"].Current;
                    if (dataRowView != null)
                    {
                        dsChanges.Orders.Rows.Add(dataRowView.Row.ItemArray);
                    }


                    // copy juga detail record dari main dataset
                    for (var i = 0; i < dsCore1.OrderDetails.Rows.Count; i++)
                    {
                        dsChanges.OrderDetails.Rows.Add(dsCore1.OrderDetails.Rows[i].ItemArray);
                    }

                    // persist changes to database
                    daOrders1.Update(dsChanges.Orders);
                    daOrderDetails1.Update(dsChanges.OrderDetails);

                    // inform user, successful
                    DialogResult dr = RibbonMessageBox.Show("Data SUCCESFULLY saved to database\n" +
                                                            "Do you want to print this document?\n",
                                                            Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    // ask user for voucher print
                    if (dr == DialogResult.Yes)
                    {
                        Cursor = Cursors.AppStarting;
                        Form fx = new frmReportViewer1(ReportHelper1.LoadSalesQuotationForm(c1TextBox1.Text));
                        fx.WindowState = FormWindowState.Maximized;
                        fx.ShowDialog();
                        Cursor = Cursors.Default;
                    }
                }
                else
                {
                    // persist changes to database
                    daOrders1.Update(dsCore1.Orders);
                    daOrderDetails1.Update(dsCore1.OrderDetails);

                    // inform user for successful update
                    RibbonMessageBox.Show("Changes SUCCESFULLY saved to database",
                                          Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                // success, close form
                btnClose.PerformClick();
            }
            catch (SqlException ex)
            {
                // textfile logging
                Logger.ErrorRoutine(ex);

                // screen logging
                if (ex.Number != 2601)
                {
                    RibbonMessageBox.Show("ERROR Saving Data: \n" + ex.Message,
                                          Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    RibbonMessageBox.Show("ERROR Saving Data:\n" +
                                          "Document number [" + c1TextBox1.Text + "]already existed in database\n" +
                                          "Please change this document number and try saving again.",
                                          Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex)
            {
                // textfile logging
                Logger.ErrorRoutine(ex);

                // screen logging
                RibbonMessageBox.Show("ERROR Saving Data: \n" + ex.Message,
                                      Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            Cursor = Cursors.Default;
        }