public List<PriceList> GetPriceListByCriteria(DateTime from, DateTime to, string supplierID, string destinationID, string customerID, string recipientID, string stuffingID, byte isSupplier, string typeContID) { List<PriceList> listPriceList = null; try { using (SqlConnection con = new SqlConnection(VisitaJayaPerkasa.Constant.VisitaJayaPerkasaApplication.connectionString)) { Constant.VisitaJayaPerkasaApplication.anyConnection = false; con.Open(); Constant.VisitaJayaPerkasaApplication.anyConnection = true; string addCriteria; if(isSupplier == 1) addCriteria = "(price_customer is null OR price_customer = 0) "; else addCriteria = "(price_supplier is null OR price_supplier = 0) AND type_cont_id like '" + typeContID + "' "; //issupplier == 1 so, is search from supplier using (SqlCommand command = new SqlCommand( "SELECT p.*, (SELECT TOP 1 supplier_name FROM supplier s WHERE s.supplier_id = p.supplier_id) as supplierName FROM [Price] p WHERE " + "((cast(dateFrom as date) <= cast('" + Utility.Utility.ConvertDateToString(from) + "' as date) " + "AND cast(dateto as date) >= cast('" + Utility.Utility.ConvertDateToString(from) + "' as date)) " + "OR " + "(cast(dateFrom as date) >= cast('" + Utility.Utility.ConvertDateToString(from) + "' as date) " + "AND cast(dateFrom as date) <= cast('" + Utility.Utility.ConvertDateToString(to) + "' as date))) " + "AND supplier_id like '%" + supplierID + "%' AND destination like '%" + destinationID + "%' " + "AND customer_id like '%" + customerID + "%' AND recipient_id like '%" + recipientID + "%' " + "AND stuffing_id like '%" + stuffingID + "%' AND " + addCriteria + "ORDER BY dateFrom" , con)) { SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { PriceList objPriceList = new PriceList(); objPriceList.ID = Utility.Utility.ConvertToUUID(reader.GetValue(0).ToString()); objPriceList.DateFrom = reader.GetDateTime(1); objPriceList.DateTo = Utility.Utility.IsDBNull(reader.GetValue(2)) ? Utility.Utility.DefaultDateTime() : reader.GetDateTime(2); objPriceList.SupplierID = Utility.Utility.ConvertToUUID(reader.GetValue(3).ToString()); objPriceList.Destination = Utility.Utility.ConvertToUUID(reader.GetValue(4).ToString()); objPriceList.TypeID = Utility.Utility.ConvertToUUID(reader.GetValue(5).ToString()); objPriceList.ConditionID = Utility.Utility.ConvertToUUID(reader.GetValue(6).ToString()); objPriceList.PriceSupplier = Utility.Utility.IsDBNull(reader.GetValue(7)) ? 0 : reader.GetDecimal(7); objPriceList.CustomerID = Utility.Utility.ConvertToUUID(reader.GetValue(8).ToString()); objPriceList.PriceCustomer = Utility.Utility.IsDBNull(reader.GetValue(9)) ? 0 : reader.GetDecimal(9); objPriceList.StuffingID = Utility.Utility.ConvertToUUID(reader.GetValue(10).ToString()); objPriceList.Recipient = Utility.Utility.ConvertToUUID(reader.GetValue(11).ToString()); objPriceList.PriceCourier = Utility.Utility.IsDBNull(reader.GetValue(12)) ? 0 : reader.GetDecimal(12); objPriceList.Item = Utility.Utility.IsDBNull(reader.GetValue(13)) ? null : reader.GetString(13); objPriceList.SupplierName = Utility.Utility.IsDBNull(reader.GetValue(14)) ? null : reader.GetString(14); if (listPriceList == null) listPriceList = new List<PriceList>(); listPriceList.Add(objPriceList); objPriceList = null; } } } } catch (Exception e) { Logging.Error("SqlPriceListRepository.cs - GetPriceListByDate() " + e.Message); } return listPriceList; }
private void btnSaveGrid_Click(object sender, EventArgs e) { if (PriceListGridView.RowCount > 0) { List<VisitaJayaPerkasa.Entities.PriceList> tempPriceList = new List<VisitaJayaPerkasa.Entities.PriceList>(); if (cboTypeSupplier.Text.ToLower().Equals("shipping lines")) { for (int i = 0; i < PriceListGridView.RowCount; i++) { VisitaJayaPerkasa.Entities.PriceList objPriceList = new VisitaJayaPerkasa.Entities.PriceList(); string id = (PriceListGridView.Rows[i].Cells[0].Value.ToString().Equals("")) ? Guid.Empty.ToString() : PriceListGridView.Rows[i].Cells[0].Value.ToString(); objPriceList.ID = Utility.Utility.ConvertToUUID(id); id = (PriceListGridView.Rows[i].Cells[1].Value.ToString().Equals("")) ? Utility.Utility.DefaultDateTime().ToString() : PriceListGridView.Rows[i].Cells[1].Value.ToString(); objPriceList.DateFrom = Utility.Utility.ConvertStringToDate(id); if (objPriceList.DateFrom.ToString().Equals(Utility.Utility.DefaultDateTime().ToString())) { MessageBox.Show(this, "Please fill date from in line " + i, "Information"); return; } id = (PriceListGridView.Rows[i].Cells[2].Value.ToString().Equals("")) ? Utility.Utility.DefaultDateTime().ToString() : PriceListGridView.Rows[i].Cells[2].Value.ToString(); objPriceList.DateTo = Utility.Utility.ConvertStringToDate(id); if (objPriceList.DateTo.ToString().Equals(Utility.Utility.DefaultDateTime().ToString())) { MessageBox.Show(this, "Please fill date to in line " + i, "Information"); return; } id = (PriceListGridView.Rows[i].Cells[5].Value.ToString().Equals("")) ? Guid.Empty.ToString() : PriceListGridView.Rows[i].Cells[5].Value.ToString(); objPriceList.TypeID = Utility.Utility.ConvertToUUID(id); if (objPriceList.TypeID.ToString().Equals(Guid.Empty.ToString())) { MessageBox.Show(this, "Please fill type in line " + i, "Information"); return; } id = (PriceListGridView.Rows[i].Cells[6].Value.ToString().Equals("")) ? Guid.Empty.ToString() : PriceListGridView.Rows[i].Cells[6].Value.ToString(); objPriceList.ConditionID = Utility.Utility.ConvertToUUID(id); if (objPriceList.ConditionID.ToString().Equals(Guid.Empty)) { MessageBox.Show(this, "Please fill condition in line " + i, "Information"); return; } id = (PriceListGridView.Rows[i].Cells[9].Value.ToString().Equals("")) ? "-1" : PriceListGridView.Rows[i].Cells[9].Value.ToString(); objPriceList.PriceSupplier = Utility.Utility.ConvertStringToDecimal(id); if (objPriceList.PriceSupplier.ToString().Equals("-1")) { MessageBox.Show(this, "Please fill price supplier in line and check your price in line " + i, "Information"); return; } if (objPriceList.DateFrom.Date > objPriceList.DateTo.Date) { MessageBox.Show(this, "Please correct datefrom and dateto in line " + i, "Information"); return; } tempPriceList.Add(objPriceList); objPriceList = null; } for (int i = 0; i < tempPriceList.Count; i++) { for (int j = i+1; j < tempPriceList.Count; j++) { if ( ( tempPriceList.ElementAt(i).TypeID.ToString().Equals(tempPriceList.ElementAt(j).TypeID.ToString()) && tempPriceList.ElementAt(i).ConditionID.ToString().Equals(tempPriceList.ElementAt(j).ConditionID.ToString()) ) && ( ( tempPriceList.ElementAt(i).DateFrom <= tempPriceList.ElementAt(j).DateFrom && tempPriceList.ElementAt(i).DateTo >= tempPriceList.ElementAt(j).DateFrom ) || ( tempPriceList.ElementAt(i).DateFrom >= tempPriceList.ElementAt(j).DateFrom && tempPriceList.ElementAt(i).DateFrom <= tempPriceList.ElementAt(j).DateTo ) ) ) { MessageBox.Show(this, "Please fix record - " + i + " and record -" + j + " have same record of date, type and condition. Please remove one", "Information"); return; } } } sqlPriceListRepository = new SqlPriceListRepository(); listPriceDeleteExistsData.Clear(); listIndexPriceDeleteExistsData.Clear(); List<int> indexDeleted = new List<int>(); for (int i = 0; i < tempPriceList.Count; i++) { Guid exists = Guid.Empty; exists = sqlPriceListRepository.GetPriceCustomerByShippingLines(tempPriceList.ElementAt(i).DateFrom, tempPriceList.ElementAt(i).DateTo, tempPriceList.ElementAt(i).TypeID.ToString(), tempPriceList.ElementAt(i).ConditionID.ToString(), cbSupplier.SelectedValue.ToString(), cbDestination.SelectedValue.ToString(), searchResultCustomer.ID.ToString()); if (!Constant.VisitaJayaPerkasaApplication.anyConnection) MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); else if (! exists.ToString().Equals(Guid.Empty.ToString())) { DialogResult dResult = MessageBox.Show(this, "Record - " + i + " has already exist. \n If you don't want to override this data, so your data not will be save. \n Do you want to override ?", "Confirmation", MessageBoxButtons.YesNo); if (dResult == DialogResult.Yes){ listPriceDeleteExistsData.Add(exists); listIndexPriceDeleteExistsData.Add(i); } else indexDeleted.Add(i); } } for (int i = indexDeleted.Count - 1; i >= 0; i--) tempPriceList.RemoveAt(indexDeleted.ElementAt(i)); for (int i = 0; i < listPriceDeleteExistsData.Count; i++) { for (int j = i+1; j < listPriceDeleteExistsData.Count; j++) { if (listPriceDeleteExistsData.ElementAt(i) == listPriceDeleteExistsData.ElementAt(j)) { MessageBox.Show(this, "Please fix record -" + listIndexPriceDeleteExistsData.ElementAt(i) + " and record -" + listIndexPriceDeleteExistsData.ElementAt(j) + " have same record of date, type and condition. Please remove one", "Information"); return; } } } sqlPriceListRepository = null; } else if (cboTypeSupplier.Text.ToLower().Equals("dooring agent")) { for (int i = 0; i < PriceListGridView.RowCount; i++) { VisitaJayaPerkasa.Entities.PriceList objPriceList = new VisitaJayaPerkasa.Entities.PriceList(); string id = (PriceListGridView.Rows[i].Cells[0].Value.ToString().Equals("")) ? Guid.Empty.ToString() : PriceListGridView.Rows[i].Cells[0].Value.ToString(); objPriceList.ID = Utility.Utility.ConvertToUUID(id); id = (PriceListGridView.Rows[i].Cells[1].Value.ToString().Equals("")) ? Utility.Utility.DefaultDateTime().ToString() : PriceListGridView.Rows[i].Cells[1].Value.ToString(); objPriceList.DateFrom = Utility.Utility.ConvertStringToDate(id); if (objPriceList.DateFrom.ToString().Equals(Utility.Utility.DefaultDateTime().ToString())) { MessageBox.Show(this, "Please fill date from in line " + i, "Information"); return; } id = (PriceListGridView.Rows[i].Cells[2].Value.ToString().Equals("")) ? Utility.Utility.DefaultDateTime().ToString() : PriceListGridView.Rows[i].Cells[2].Value.ToString(); objPriceList.DateTo = Utility.Utility.ConvertStringToDate(id); if (objPriceList.DateTo.ToString().Equals(Utility.Utility.DefaultDateTime().ToString())) { MessageBox.Show(this, "Please fill date to in line " + i, "Information"); return; } id = (PriceListGridView.Rows[i].Cells[5].Value.ToString().Equals("")) ? Guid.Empty.ToString() : PriceListGridView.Rows[i].Cells[5].Value.ToString(); objPriceList.TypeID = Utility.Utility.ConvertToUUID(id); if (objPriceList.TypeID.ToString().Equals(Guid.Empty.ToString())) { MessageBox.Show(this, "Please fill type in line " + i, "Information"); return; } id = (PriceListGridView.Rows[i].Cells[9].Value.ToString().Equals("")) ? "-1" : PriceListGridView.Rows[i].Cells[9].Value.ToString(); objPriceList.PriceSupplier = Utility.Utility.ConvertStringToDecimal(id); if (objPriceList.PriceSupplier.ToString().Equals("-1")) { MessageBox.Show(this, "Please fill price supplier in line and check your price in line " + i, "Information"); return; } if (objPriceList.DateFrom.Date > objPriceList.DateTo.Date) { MessageBox.Show(this, "Please correct datefrom and dateto in line " + i, "Information"); return; } tempPriceList.Add(objPriceList); objPriceList = null; } for (int i = 0; i < tempPriceList.Count; i++) { for (int j = i + 1; j < tempPriceList.Count; j++) { if ( ( tempPriceList.ElementAt(i).TypeID.ToString().Equals(tempPriceList.ElementAt(j).TypeID.ToString()) ) && ( ( tempPriceList.ElementAt(i).DateFrom <= tempPriceList.ElementAt(j).DateFrom && tempPriceList.ElementAt(i).DateTo >= tempPriceList.ElementAt(j).DateFrom ) || ( tempPriceList.ElementAt(i).DateFrom >= tempPriceList.ElementAt(j).DateFrom && tempPriceList.ElementAt(i).DateFrom <= tempPriceList.ElementAt(j).DateTo ) ) ) { MessageBox.Show(this, "Please fix record - " + i + " and record -" + j + " have same record of date and type. Please remove one", "Information"); return; } } } sqlPriceListRepository = new SqlPriceListRepository(); listPriceDeleteExistsData.Clear(); listIndexPriceDeleteExistsData.Clear(); List<int> indexDeleted = new List<int>(); for (int i = 0; i < tempPriceList.Count; i++) { Guid exists = Guid.Empty; exists = sqlPriceListRepository.GetPriceCustomerByDooringAgent( tempPriceList.ElementAt(i).DateFrom, tempPriceList.ElementAt(i).DateTo, tempPriceList.ElementAt(i).TypeID.ToString(), cbSupplier.SelectedValue.ToString(), cbDestination.SelectedValue.ToString(), cboRecipient.SelectedValue.ToString()); if (!Constant.VisitaJayaPerkasaApplication.anyConnection) MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); else if (!exists.ToString().Equals(Guid.Empty.ToString())) { DialogResult dResult = MessageBox.Show(this, "Record - " + i + " has already exist. \n If you don't want to override this data, so your data not will be save. \n Do you want to override ?", "Confirmation", MessageBoxButtons.YesNo); if (dResult == DialogResult.Yes){ listPriceDeleteExistsData.Add(exists); listIndexPriceDeleteExistsData.Add(i); } else indexDeleted.Add(i); } } for (int i = indexDeleted.Count - 1; i >= 0; i--) tempPriceList.RemoveAt(indexDeleted.ElementAt(i)); for (int i = 0; i < listPriceDeleteExistsData.Count; i++) { for (int j = i + 1; j < listPriceDeleteExistsData.Count; j++) { if (listPriceDeleteExistsData.ElementAt(i) == listPriceDeleteExistsData.ElementAt(j)) { MessageBox.Show(this, "Please fix record -" + listIndexPriceDeleteExistsData.ElementAt(i) + " and record -" + listIndexPriceDeleteExistsData.ElementAt(j) + " have same record of date and type. Please remove one", "Information"); return; } } } sqlPriceListRepository = null; } else if (cboTypeSupplier.Text.ToLower().Equals("trucking")) { for (int i = 0; i < PriceListGridView.RowCount; i++) { VisitaJayaPerkasa.Entities.PriceList objPriceList = new VisitaJayaPerkasa.Entities.PriceList(); string id = (PriceListGridView.Rows[i].Cells[0].Value.ToString().Equals("")) ? Guid.Empty.ToString() : PriceListGridView.Rows[i].Cells[0].Value.ToString(); objPriceList.ID = Utility.Utility.ConvertToUUID(id); id = (PriceListGridView.Rows[i].Cells[1].Value.ToString().Equals("")) ? Utility.Utility.DefaultDateTime().ToString() : PriceListGridView.Rows[i].Cells[1].Value.ToString(); objPriceList.DateFrom = Utility.Utility.ConvertStringToDate(id); if (objPriceList.DateFrom.ToString().Equals(Utility.Utility.DefaultDateTime().ToString())) { MessageBox.Show(this, "Please fill date from in line " + i, "Information"); return; } id = (PriceListGridView.Rows[i].Cells[2].Value.ToString().Equals("")) ? Utility.Utility.DefaultDateTime().ToString() : PriceListGridView.Rows[i].Cells[2].Value.ToString(); objPriceList.DateTo = Utility.Utility.ConvertStringToDate(id); if (objPriceList.DateTo.ToString().Equals(Utility.Utility.DefaultDateTime().ToString())) { MessageBox.Show(this, "Please fill date to in line " + i, "Information"); return; } id = (PriceListGridView.Rows[i].Cells[5].Value.ToString().Equals("")) ? Guid.Empty.ToString() : PriceListGridView.Rows[i].Cells[5].Value.ToString(); objPriceList.TypeID = Utility.Utility.ConvertToUUID(id); if (objPriceList.TypeID.ToString().Equals(Guid.Empty.ToString())) { MessageBox.Show(this, "Please fill type in line " + i, "Information"); return; } id = (PriceListGridView.Rows[i].Cells[9].Value.ToString().Equals("")) ? "-1" : PriceListGridView.Rows[i].Cells[9].Value.ToString(); objPriceList.PriceSupplier = Utility.Utility.ConvertStringToDecimal(id); if (objPriceList.PriceSupplier.ToString().Equals("-1")) { MessageBox.Show(this, "Please fill price supplier in line and check your price in line " + i, "Information"); return; } id = (PriceListGridView.Rows[i].Cells[12].Value.ToString().Equals("")) ? "-1" : PriceListGridView.Rows[i].Cells[12].Value.ToString(); objPriceList.PriceCourier = Utility.Utility.ConvertStringToDecimal(id); if (objPriceList.PriceCourier.ToString().Equals("-1")) { MessageBox.Show(this, "Please fill price courier in line and check your price in line " + i, "Information"); return; } if (objPriceList.DateFrom.Date > objPriceList.DateTo.Date) { MessageBox.Show(this, "Please correct datefrom and dateto in line " + i, "Information"); return; } tempPriceList.Add(objPriceList); objPriceList = null; } for (int i = 0; i < tempPriceList.Count; i++) { for (int j = i + 1; j < tempPriceList.Count; j++) { if ( ( tempPriceList.ElementAt(i).TypeID.ToString().Equals(tempPriceList.ElementAt(j).TypeID.ToString()) ) && ( ( tempPriceList.ElementAt(i).DateFrom <= tempPriceList.ElementAt(j).DateFrom && tempPriceList.ElementAt(i).DateTo >= tempPriceList.ElementAt(j).DateFrom ) || ( tempPriceList.ElementAt(i).DateFrom >= tempPriceList.ElementAt(j).DateFrom && tempPriceList.ElementAt(i).DateFrom <= tempPriceList.ElementAt(j).DateTo ) ) ) { MessageBox.Show(this, "Please fix record - " + i + " and record -" + j + " have same record of date and type. Please remove one", "Information"); return; } } } sqlPriceListRepository = new SqlPriceListRepository(); listPriceDeleteExistsData.Clear(); listIndexPriceDeleteExistsData.Clear(); List<int> indexDeleted = new List<int>(); for (int i = 0; i < tempPriceList.Count; i++) { Guid exists = Guid.Empty; exists = sqlPriceListRepository.GetPriceCustomerByTrucking(tempPriceList.ElementAt(i).DateFrom, tempPriceList.ElementAt(i).DateTo, tempPriceList.ElementAt(i).TypeID.ToString(), cbSupplier.SelectedValue.ToString(), searchResultCustomer.ID.ToString(), cboStuffingPlace.SelectedValue.ToString()); if (!Constant.VisitaJayaPerkasaApplication.anyConnection) MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); else if (!exists.ToString().Equals(Guid.Empty.ToString())) { DialogResult dResult = MessageBox.Show(this, "Record - " + i + " has already exist. \n If you don't want to override this data, so your data not will be save. \n Do you want to override ?", "Confirmation", MessageBoxButtons.YesNo); if (dResult == DialogResult.Yes){ listPriceDeleteExistsData.Add(exists); listIndexPriceDeleteExistsData.Add(i); } else indexDeleted.Add(i); } } for (int i = indexDeleted.Count - 1; i >= 0; i--) tempPriceList.RemoveAt(indexDeleted.ElementAt(i)); for (int i = 0; i < listPriceDeleteExistsData.Count; i++) { for (int j = i + 1; j < listPriceDeleteExistsData.Count; j++) { if (listPriceDeleteExistsData.ElementAt(i) == listPriceDeleteExistsData.ElementAt(j)) { MessageBox.Show(this, "Please fix record -" + listIndexPriceDeleteExistsData.ElementAt(i) + " and record -" + listIndexPriceDeleteExistsData.ElementAt(j) + " have same record of date and type. Please remove one", "Information"); return; } } } sqlPriceListRepository = null; } /* else if (cboTypeSupplier.Text.ToLower().Equals("general")) { for (int i = 0; i < PriceListGridView.RowCount; i++) { VisitaJayaPerkasa.Entities.PriceList objPriceList = new VisitaJayaPerkasa.Entities.PriceList(); string id = (PriceListGridView.Rows[i].Cells[0].Value.ToString().Equals("")) ? Guid.Empty.ToString() : PriceListGridView.Rows[i].Cells[0].Value.ToString(); objPriceList.ID = Utility.Utility.ConvertToUUID(id); id = (PriceListGridView.Rows[i].Cells[1].Value.ToString().Equals("")) ? Utility.Utility.DefaultDateTime().ToString() : Utility.Utility.ChangeDateMMDD(PriceListGridView.Rows[i].Cells[1].Value.ToString()); objPriceList.DateFrom = Utility.Utility.ConvertStringToDate(id); if (objPriceList.DateFrom.ToString().Equals(Utility.Utility.DefaultDateTime().ToString())) { MessageBox.Show(this, "Please fill date from in line " + i, "Information"); return; } id = (PriceListGridView.Rows[i].Cells[2].Value.ToString().Equals("")) ? Utility.Utility.DefaultDateTime().ToString() : Utility.Utility.ChangeDateMMDD(PriceListGridView.Rows[i].Cells[2].Value.ToString()); objPriceList.DateFrom = Utility.Utility.ConvertStringToDate(id); if (objPriceList.DateFrom.ToString().Equals(Utility.Utility.DefaultDateTime().ToString())) { MessageBox.Show(this, "Please fill date to in line " + i, "Information"); return; } id = (PriceListGridView.Rows[i].Cells[8].Value.ToString().Equals("")) ? "-1" : PriceListGridView.Rows[i].Cells[8].Value.ToString(); objPriceList.PriceSupplier = Utility.Utility.ConvertStringToDecimal(id); if (objPriceList.PriceSupplier.ToString().Equals("-1")) { MessageBox.Show(this, "Please fill price supplier in line and check your price in line " + i, "Information"); return; } if (objPriceList.DateFrom.Date > objPriceList.DateTo.Date) { MessageBox.Show(this, "Please correct datefrom and dateto in line " + i, "Information"); return; } tempPriceList.Add(objPriceList); objPriceList = null; } for (int i = 0; i < tempPriceList.Count; i++) { for (int j = i + 1; j < tempPriceList.Count; j++) { if (PriceListGridView.Rows[i].Cells[1].Value.ToString().Equals(PriceListGridView.Rows[j].Cells[1].Value.ToString()) && PriceListGridView.Rows[i].Cells[2].Value.ToString().Equals(PriceListGridView.Rows[j].Cells[2].Value.ToString())) { MessageBox.Show(this, "Record -" + i + " and record -" + j + " have same record of date. Please remove one", "Information"); return; } } } } */ SqlParameter[] sqlParamDeletedPrice = null; SqlParameter[] sqlParamInsert = null; if (listPriceDeleteExistsData.Count > 0) { string[] key = new string[listPriceDeleteExistsData.Count]; object[] value = new object[listPriceDeleteExistsData.Count]; for (int j = 0; j < listPriceDeleteExistsData.Count; j++) { key[j] = "priceID"; value[j] = listPriceDeleteExistsData.ElementAt(j); } sqlParamDeletedPrice = SqlUtility.SetSqlParameter(key, value); } if (tempPriceList.Count > 0) { //14 is field who any in below for string[] key = new string[tempPriceList.Count * 14]; object[] value = new object[tempPriceList.Count * 14]; int nn = 0; for (int j = 0; j < tempPriceList.Count; j++) { key[nn] = "price_id"; value[nn++] = Guid.NewGuid(); key[nn] = "dateFrom"; value[nn++] = tempPriceList.ElementAt(j).DateFrom; key[nn] = "dateTo"; value[nn++] = tempPriceList.ElementAt(j).DateTo; key[nn] = "supplier_id"; if (cbSupplier.SelectedIndex >= 0) value[nn++] = listSupplier[cbSupplier.SelectedIndex].Id; else value[nn++] = Guid.Empty; key[nn] = "destination"; if (cbDestination.SelectedIndex >= 0) value[nn++] = listCity[cbDestination.SelectedIndex].ID; else value[nn++] = Guid.Empty; key[nn] = "type_cont_id"; value[nn++] = tempPriceList.ElementAt(j).TypeID; key[nn] = "condition_id"; value[nn++] = tempPriceList.ElementAt(j).ConditionID; key[nn] = "price_supplier"; value[nn++] = tempPriceList.ElementAt(j).PriceSupplier; key[nn] = "customer_id"; if (searchResultCustomer != null) value[nn++] = searchResultCustomer.ID; else value[nn++] = Guid.Empty; key[nn] = "price_customer"; value[nn++] = tempPriceList.ElementAt(j).PriceCustomer; key[nn] = "stuffing_id"; if (cboStuffingPlace.SelectedIndex >= 0) value[nn++] = listWarehouse[cboStuffingPlace.SelectedIndex].Id; else value[nn++] = Guid.Empty; key[nn] = "recipient_id"; if (cboRecipient.SelectedIndex >= 0) value[nn++] = listRecipient[cboRecipient.SelectedIndex].ID; else value[nn++] = Guid.Empty; key[nn] = "price_courier"; value[nn++] = tempPriceList.ElementAt(j).PriceCourier; key[nn] = "item"; value[nn++] = DBNull.Value; } sqlParamInsert = SqlUtility.SetSqlParameter(key, value); if (sqlPriceListRepository == null) sqlPriceListRepository = new SqlPriceListRepository(); if (sqlPriceListRepository.SavePriceList( (sqlParamDeletedPrice == null) ? null : sqlParamDeletedPrice, sqlParamInsert)) { MessageBox.Show(this, "Success saving !", "Information"); listPriceDeleteExistsData.Clear(); listIndexPriceDeleteExistsData.Clear(); } else if (!Constant.VisitaJayaPerkasaApplication.anyConnection) { MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { MessageBox.Show(this, "Failed save data !", "Information"); return; } } PriceListGridView.Rows.Clear(); PriceListGridView.Enabled = false; } }